alt
Advertisement
Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow VB.NET 2005 arrow .NET Common Windows Forms Controls Part 1
Site Search


.NET Common Windows Forms Controls Part 1
Article Index
.NET Common Windows Forms Controls Part 1
Page 2
Page 3

.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




 
< 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