Exforsys.com
 
Home Tutorials VB.NET 2005
 

.NET Common Windows Forms Controls Part 1

 

.NET Common Windows Forms Controls Part 1 - Page 3

Page 3 of 3


.


.



Buttons

Buttons provide for the most common way of creating and handling events in the code. It exposes the common properties and the methods that help us use this control.


CheckBoxes

Check Boxes are controls that you click to select it and click it again to deselect it. This control can be ideally used when getting user input for answers of the type yes or no. Open a new project and on the Form1 you can add three check boxes, a label and a command button. Type the following codes in the code behind form:


Click here for the Sample Code


The following screenshots illustrate the performance of the program:


The screenshot shown below shows the initial screen. Note the label message that says that you have not clicked on any of the check box:



The following screenshot shows that the checkbox two is clicked:



The following screenshot shows that the checkbox is unchecked and label message has changed:



RadioButtons


Radio buttons are also checkboxes and the difference lies in the following areas:


1. They are round as against the checkboxes which are square

2. they are used mostly in groups


While checkboxes are used individually, the radiobuttons are use in groups. In case of the radiobuttons, if you check button 3 after clicking button1 the button1 is deselected automatically.


Let us see an illustration: The following code gives the demo for the radiobutton:


Click here for the Sample Code


The following screenshot shows the output:




ListBox

A List box is a useful tool that helps you to display a list of several items from which you can select one or more. A scrollbar is automatically added to the list box when the number of items in the list box increases.


1. To a new Form add a listbox from the toolbox.

2. Locate the property items in the property sheet.

3. Click on the collections on the other side.

4. A new dialog box is opened.

5. Add the items to this dialog box.

6. You must type one item per line.

7. On closing the dialog box the items added to the listbox are available.

8. Enter the following lines of code in the code.


Public Class Form1


Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged


Label1.Text = "Item " & ListBox1.SelectedIndex + 1 & " is Selected"


End Sub


End Class


Now if you execute the program by pressing F5, you will see the following output:



You can also add items to the listbox at runtime by using the following line of code:

Listbox1.Items.Add(“Item10”)

In the same way you can also remove the items from the the listbox:

Listbox1.Items.Remove(ListBox1.SelectedItem)


Checked listbox

Checked listbox is derived from standard listbox control. In this case you can see a check box at the side of the item list. To check an item, the user has to double-click a checkbox by default. But you can also do it by single click if you set the CheckOnClick property to true. A screenshot of the application executed is given below:



ComboBox

This control is a frequently used control. This control is made up of two parts. The top part is a text box that allows user to enter data. The other part is a list box that allows the user to select from the items listed. You can allow the user to type in an item or select an item from the list. The SelectedItems proper

First Page: .NET Common Windows Forms Controls Part 1


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

Puneet Kumar said:

  In this form showing above, suppose I type something in Textbox1. and then after pressing the Enter key, I want the Focus should be in the Textbox2.

So please can U tell me the What is the Event or Focusing is required for that thing
March 13, 2010, 6:50 am

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