accounting software visual basic c#



Benefits
faq accounting software database programming
Benefits

C# visual basic 2005 User Controls Windows forms controls are controls that are used in windows applications. These are also referred to as User Controls.

Creating Custom Controls in visual basic 2005 and C# Custom controls are controls created by you. There are two ways to do this. One is from scratch, using the base classes. The other method is to derieve from existing controls and enhance functionality. RAD of UI User controls allow encapsulatin of UI design. This allows rapid application development of UI. For instance, if every control has a name property, then by creating custom controls, we can eliminate the process of setting name property for repeatatively. While this is a basic functionality of custom controls, Windows classes provide higher level of functionality to push RAD to a new high level.

Steps to create a Custom Control 1.Select File - New - Project option to open the New project dialog box.
2.Select Visual Basic in project types and Windows Control Library in Template List. Enter 'MyControl' and click Ok.

user control project

3.By default, the name of the user control is UserControl1.
4.In the Solution Explorer window, click the UserControl1 and change the name as MyControl. Save the project.

We will now create a user control which accepts the Code and Name of the Customer.
5.Place the controls by dragging two textbox controls and two label controls on the form and set their text properties as follows. Label1 - Code, Label2 - Name, TextBox1 - txtCode, TextBox2 - txtName.

user control form

We will now write the code for the control MyControl.

Writing properties to the control.

User control is implemented as a class. So, we can write properties, methods and events just like in a class. There are two ways to access user control's properties. Declare public variables or use property procedures. We don't write public variables since it is against object-oriented programming practice.

Writing methods to a control

Exposing a function or procedure from a user control is just like a exposing function or procedure from a class. We need to declare a method as a public.

We must write the following code in the MyControl class.

6. We will test the execution of user control by running the project. The user control will be displayed in a test container dialog box as shown in Fig below. We can test this control by entering data in code and name textbox controls and checking to see whether the result is as we desire. Click the Close button in the Test Container Dialog box. Note that the control was automatically added to the toolbox in the 'MyControl' control component tab. Once the control is added to the toolbox, we can use the control in applications like any other control in the toolbox. However, it is evident, only after we add a windows application to this solution 'MyControl'.

user control TestContainer dialog

We will now add a new user control to a form.

a.Choose File - Add - New project and in the Add New project Dialog box, select windows application in the Template pane and enter name as ValidateControl and then click Ok.
b.Now add 'MyControl' user control in the components tab of the toolbox and place it on the Form1 as shown in Fig. Form1 is the default form given by Visual Basic. Place a button control and name it as btnValidate.

place user control on the form

c.Write the code in Form1 as below d.Use the Solution Explorer and set the ValidateControl project as the Startup project using the context menu. Now run the project and the control will appear on the form.
e.Click on the validate button to see the result.

7. Writing Events to a control.

We can use the system declared events in most of the situations. However, in certain situations the system defined events may not be sufficient. Suppose in the custom control we do not want to validate the user entries for the control. Then, we can raise events for user entries and allow the user to handle the event as per their requirement. For this reason, we should be able to declare events, raise events and user should be able to handle the events raised by the control.

Firstly, in the user control class, we need to declare the event and we must raise the event at the appropriate points in the code by using the RaiseEvent statement. We can, then wire an event handler in the client application.

We can see the event definition in the following code just after the class definition. The event is then raised by calling RaiseEvent statement. An event, declared and raised is detected by the form. The event will appear in the list of events for the user control.
When we click the validate button at runtime, a messgae is displayed in the event.

Free Resources

SITEMAP  |   About VKINFOTEK  |   Accounting Software Client Server  |   Accounting Software visual basic.Net Sql Server  |   Inventory Software using visual basic  |   Client Server Programming  |   Complete Programmer  |   Testimonials  |   Data  |   Object  |   Dataset  |   Middle Tier  |   Data Binding  |   Simple Data Binding  |   IT Related NEWS  |   Love and Links  |   State Management (Web Development)  |   Adodotnet Evolution  |   AJAX  |   visual basic 2005 Strings  |   Accounting Software  |   Implementing Constructors in visual basic.Net  |   Implementing Structure in visual basic.Net  |   Creating, Using Namespaces in visual basic.Net  |   What is an Assembly ?  |   How to create a Shared Assembly ?  |   Accounting Info Africa  |   About Us  |   Resume Format  |   Add to Delicious  |   Digg This !!  |   Technorati Profile
Copyright. 2001-2006.
VK Infotek Inc.
Updated on
Valid XHTML Page