Exforsys.com
 
Home Tutorials VB.NET 2005
 

.NET Common Windows Forms Controls Part 1

 

.NET Common Windows Forms Controls Part 1

Page 1 of 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




Next Page: .NET Common Windows Forms Controls Part 1 - Page 2


Read Next: DomainUpDown and NumericUpDown Controls



 

 

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.
March 1, 2007, 10:34 am

Glenn said:

  Thanks it was very helpful..
Easy to follow/understand...
Thanks a lot
December 27, 2008, 2:25 am

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?
February 25, 2009, 3:31 pm

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape