alt
Advertisement
Sponsored links
Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow VB.NET 2005 arrow Common Controls and Handling Control Events
Site Search


Common Controls and Handling Control Events
Article Index
Common Controls and Handling Control Events
Page 2

Common Controls and Handling Control Events

In this tutorial we will be learning how to use common control like Control Hierarchy, Label and LinkLabel, TextBox and RichTextBox, PictureBox, GroupBox and Panel, Button, CheckBox and RadioButton, ListBox, CheckedListBox and ComboBox, DomainUpDown and NumericUpDown, MonthCalendar and DateTimePicker, TreeView and ListView, Timer, TrackBar and ProgressBar, HScrollBar, VScrollBar, TabControl and Handling Control Events.

All controls are governed by the Control Class “System.Windows.Forms” Namespace. This class handles the entire basic window handle (HWND) functionality such as the creation and destruction of windows handles. When Control and Rich Control are integrated VB.NET provides for greater functionality.

A number of properties are shared by all controls in a class. Any change in such shared properties impacts on all controls in the class. Some of the shared properties are listed below.

DefaultBackColor: Read-only. Returns what the background color of the control would be if the background color were set explicityly

DefaultFont: Read-only. Returns what the font of the control would be if the font were set explicitly

DefaultForeColor: Read-only. Returns what the foreground color of the control would be if the fore ground color is changed.

Public Shared Properties

Public shared properties are distinct from properties that are shared by controls of a class in that the value of the property is not shared across the controls in a class. Any change in the property of a control does not result in a change in the properties of the controls in the class. Even when two instances of an object are created, each can have a distinct value assigned to a property. Examples of public instance properties are listed below for your understanding.

AccessibilityObject
Specified the AccessibleObject assigned to the control.
BackColor
Specifies the background color
Cursor
Specifies the cursor that is displayed when the mouse pointer moves over the control
Focused
Read-only. Returns whether the control currently as the input focus.
Size
Specifies the size of the control
Anchor
Specifies which edges of the control are bound to the edges of its container
Dock
Specifies to which edge of the container the control is docked. When specified, the resizing of the control is handled automatically. Controls that are “dockable” require code analyzing window movements coupled with the setting of this property
Font
Specifies the current font of the control
Location
Specifies the coordinates of the upper-left corner of the control relative to the upper-left corner of the controls container
Name
Specifies the name of the control. This value is typically used to refer to the control in code
Size
Specifies the height and width of the full control
TabIndex
Specifies this control’s place in the tab order for all controls within the same container
TabStop
Specifies whether the control can receive focus via the tab key
Visible
Specifies whether the control is visible
Enabled
Specifies whether the control is enabled. This also covers items such as receiving focus

Configuring the order of tabs

A user is required to move across a form in a prescribed order. The tab order of the control determines the way in which the cursor moves in the form and takes the user through the various options created for his use. This is a very important property for the application designer as it determines the sequence of user input if any.

Click on the control in the form and edit the TabIndex property and change its value. The value for this property is given in integers. This will be enabled only if the TabStop Property is set to true. Let us see an example for this feature.

  1. Create a new project in the visual Studio IDE and add a form.
  2. Drag and add 18 Command Buttons to this form and arrange them in a matrix.
  3. Pick any 6 of them and select them.
  4. Set the property enabled to false.
  5. This can also be done at runtime as shown in the example.
  6. Position two buttons separately as shown in the from.
  7. You can also add two labels one at the top and the other at the bottom.
  8. For each of the remaining Buttons do the following changes:
    1. From the first button on the top left change their name in order and give them a new name (First, Second … Tenth)
    2. You will find that the TabIndex value would have already been set as per the order of their placement in the form.
    3. Change their values so that the label named first will have the value 1 and the label that has the name Tenth will have a value 10.

At the bottom of the form you will have one label control and two command buttons. Set the name value for the label as null and that of the first command button to “Reverse Order!”. Let the name of the second command button be “Exit”. Now your form will look like the screenshot given below.



You have to add the following lines of code to the project:

Click here for Sample Source Code

Execute the project by pressing F5. This example illustrates the purpose of the properties and also the method used to assign the properties at run time. Please note that the property TabStop is not available to all properties. For example the controls like Label and LinkLabel do not expose this property.



 
< Prev   Next >
Exforsys Offers
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape