Sponsored Links
VB.NET 2005 Tutorials
- VB.NET 2005 Free Training
- Shared Assembly
- The .NET Framework Architecture Part 1
- Tracing VB.NET Windows Application
- The .NET Framework Architecture Part 2
- VB.NET Windows Application Testing
- Implementing Inheritance
- The File Types Editor
- Visual Studio.NET Namespaces
- Differences between VB.NET 1.0 and VB.NET 2.0
- Visual Studio Windows Forms Designer
- Introducing VB.NET Windows Forms
- Event Handling In Visual Basic .NET
- Exploring the Forms Designer generated code
- Building Graphical Interface elements
- Microsoft .NET Creating Installation Components
- Application Class and Message Class
- Visual Studio Adding Controls to Windows Form
- Common Controls and Handling Control Events
- Implementing Class Library Object
Tutorials
VB.NET 2005.NET Common Windows Forms Controls Part 1
Table of Contents
.NET Common Windows Forms Controls Part 1
.NET Common Windows Forms Controls Part 1 - Page 2
.NET Common Windows Forms Controls Part 1 - Page 3.NET Common Windows Forms Controls Part 1
.NET Common Windows Forms Controls
In this tutorial we will learn about Common Windows Forms Controls in Visual Basic .NET 2005. IN this part 1 of this article, We will be learning the controls like Control Hierarchy, Label, LinkLabel, TextBox, RichTextBox, PictureBox, GroupBox, Panel, Button, CheckBox , RadioButton, ListBox, CheckedListBox and ComboBox.
Control Hierarchy
The base class for all Windows controls is located in the System.Windows.Forms namespace. These controls are built into the .NET framework and form the basis for derived controls. These controls have a distinct hierarchy of their own. For example the hierarchy of the control rich text box is given below:
Object
MarshalByRefObject
Component
Control
TextBoxBase
RichTextBox
We shall take a quick look at some of the properties of the control:
|
Property |
Description |
|
AllowsDrop |
Value that decides to accept data dropped in to it |
|
Anchor |
Gets/Sets the value of edges of the control to be anchored |
|
BackColor |
Gets/sets value of the color of the Background |
|
CanFocus |
Returns a value which specifies id the control can receive focus |
|
DataBinding |
Gets the data bindings for the control |
|
Parent |
Gets/Sets the controls parent container |
|
Visible |
Gets/Sets the value determines the visibility of the control |
Some of the methods of the control are listed below:
|
Method |
Description |
|
BringToFront |
Brings the control to the front of the stacking |
|
Contains |
Retrieves a value specifying if the control is a child of this control |
|
Dispose |
Releases the resources used by the control |
|
GetType |
Gets the type of the control |
|
Hide |
Hides the control |
|
Invalidate |
Invalidates a part of the control and sends a paint message to the control |
|
DoDragDrop |
Starts a drag and drop operation |
Some of the events of the control are listed below:
|
BackgroundChanged |
When the value of the backColor property is changed |
|
Click |
When mouse is clicked on the control |
|
ControlAdded |
When a new control is added |
|
ControlRemoved |
When a control is removed |
|
SursorChanged |
When the cursor property value ischanged |
|
DragEnter |
When an object is dragged into the control’s bounds |
|
Enter |
When the control is entered |
|
GotFocus |
When the control receives focus |
|
Leave |
When the location property value is changed |
|
MouseWheel |
When the mouse wheel moves whild the control has focus |
|
VisibleChanged |
When the Visible property value is changed |
The above list is not exhaustive. However, a designer would find it profitable to get himself acquainted with the properties and methods of the different types of controls that he uses. Derived controls are customized controls that use the .NET framework controls as a base for building upon.
Label
The Label control is used in a number of applications to indicate the nature of the input required or the name of a control or just to convey a message to the user. The autosize property of this control is true by default, but can be dynamically fixed. Since this control cannot receive focus, it can also be used to create access keys for other controls.
Let us see a demo for this activity:
-
Draw the label first, and then draw the other control. Other wise draw the controls in any order and set the System.Windows.Forms.Control.TabIndex property of the label to one less than the other control.
-
Set the label's System.Windows.Forms.Label.UseMnemonic property to true.
-
Use an ampersand (&) in the label's System.Windows.Forms.Label.Text property to assign the access key for the label. For more information, see Creating Access Keys for Windows Forms Controls.
-
The following code will accomplish the task. Press F5 and see the demo in action.
Click here for the Sample Code
The output of the above codes is shown in the screenshot pasted below:

Link Labels
This control is similar to the Label Control. In addition to all the properties, methods, and events of the Label control, the LinkLabel control has properties for hyperlinks and link colors. The LinkLabel.LinkArea property sets the area of the text that activates the link. The LinkLabel.LinkColor, LinkLabel.VisitedLinkColor, and LinkLabel.ActiveLinkColor properties set the colors of the link. The LinkLabel.LinkClicked event determines what happens when the link text is selected.
Link Labels are labels that support hyper links. Some of the important properties and events are given below:
|
Property/Event |
Description |
|
ActiveLinkColor |
Gets/Sets the color for an active link |
|
DisabledLinkColor |
Gets/sets the color for an inactive link |
|
LinkArea |
Gets/Sets the range of that will be treated as link |
|
LinkBehaviour |
Gets/Sets the value that represents the behavior of a link |
|
LinkColor |
Gets/Sets the color of the link |
|
LinkVisited |
Gets/Sets the value specifying if a link should be displayed as though it had been visited |
|
VisitedLinkColor |
Gets/Sets the color used for the links that have been visited |
The following code snippet demonstrates the usage of the link label.
Click here for the Sample Code
TextBox
The hierarchy of the control Text Box is given below:
Object
MarshalByRefObject
Component
Control
TextBoxBase
Text Box
This control is used mainly to collect user input of data and display text. The look and feel and the behavior can be controlled by manipulating the values of its properties, invoking some methods and also handling some of the events that this control is enabled to handle.
Some of the methods, properties and events of the text box are given below:
|
Property/Method/Event |
Description |
|
AutoSize |
Sets/Gets value specifying if the control can resize itself automatically. |
|
CanUndo |
Return a value specifying if the user can undo the previous operation |
|
Modified |
Indicates if the text box control ha been modified by the user since the control was created or its contents were lost |
|
Multiline |
Sets/Gets value to determine if this is a multi-line text box control |
|
SelectiedText |
Sets/Get value for the currently selected text in the control box |
|
SelectionLength |
Sets/Gets value of number of characters selected |
|
TextAlign |
Gets/Sets how the test is aligned in the text box |
|
WordWrap |
Indicates if a multiline text box control automatically wraps the words |
|
AppendText |
Append textx to the current text in the text box |
|
Clear |
Clears all the text in the text box |
|
Copy |
Copies the selected text to the clipboard |
|
Cut |
Copies the selected text to the clip board and clears the text box |
|
Select |
Selects the text in the text box |
|
Undo |
Undoes the last edit operation in the text box |
|
AutoSizeChanged |
When the value of the autosizeproperty is changed |
|
Click |
When the text box is clicked |
|
ReadonlyChanged |
When the value of the readOnly property changed |
Next Page: .NET Common Windows Forms Controls Part 1 - Page 2
Comments
Marie Nedland said:
| I thought this was very useful but I was hoping for a little more information on the common controls of VB.Net 2005...such as the DateTimePicker, ListView, MaskedTextBox, MonthCalendar, NotifyIcon, ProgressBar, ToolTip, TreeView, and the WebBrowser tools. I mean they are listed under the common controls but I can hardly find any articles about them. |
Glenn said:
|
Thanks it was very helpful.. Easy to follow/understand... Thanks a lot |
Bob said:
| That was piggin' useless, you just stated the obvious, VS explains all that to you anyway, can you tell us how to program a button, to take user input from text boxes, combo boxes and masked text boxes, store it, then take text data from a database, and merge it with the users input data, and then display it all on screen? |
Sponsored Links
