alt
Advertisement

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



.NET Common Windows Forms Controls Part 1
Article Index
.NET Common Windows Forms Controls Part 1
Page 2
Page 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 property gets the selected list item. If no item is selected then the selected index has a value -1. The selected index value for the first item is 0. The following screenshot shows the illustration for the Combobox.


Trackback(0)
Comments (1)add comment

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 01, 2007

Write comment

busy

 
< Prev   Next >
Sponsored Links
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape