Tutorials
VB.NET 2005
Common Controls and Handling Control Events
Common Controls and Handling Control Events - Page 2In 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 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
|
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.
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:
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.
Next Page: Common Controls and Handling Control Events - Page 2