(AN AUTONOMOUS UNIT OF RANCHI UNIVERSITY FROM 2009)
- Prakash Kumar, Dept. of CA
-Raju Manjhi, Dept of CA
__________________________________________________________________________________
Note:
Go through the video and practice
Try ComboBox by your own( NOT included in video)
Windows.Forms. Controls
1. Button
The Windows Forms Button
control allows the user to click it to perform an action. When the button is
clicked, it looks as if it is being pushed in and released. Whenever the user
clicks a button, the Click event handler is invoked.
Public Class Form1
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("Button1 was
clicked")
End Sub
End Class
2. CheckBox
The Windows Forms CheckBox control indicates whether a particular
condition is on or off. It is commonly used to present a Yes/No or True/False
selection to the user. You can use check box controls in groups to display
multiple choices from which the user can select one or more.
Public Class Form1
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True And
CheckBox2.Checked = False Then
MsgBox("CheckBox1 is
Selected")
ElseIf CheckBox2.Checked = True And
CheckBox1.Checked = False Then
MsgBox("CheckBox2 is
Selected")
ElseIf CheckBox1.Checked = True And
CheckBox2.Checked = True Then
MsgBox("Both CheckBox is
Selected")
Else
CheckBox1.Checked = False And CheckBox2.Checked = False
MsgBox("No CheckBox is
Selected")
End If
End Sub
End Class
3. ListBox
A Windows Forms ListBox
control displays a list from which the user can select one or more items. If
the total number of items exceeds the number that can be displayed, a scroll
bar is automatically added to the ListBox control. When the MultiColumn
property is set to true, the list box displays items in multiple columns
and a horizontal scroll bar appears. When the MultiColumn property is
set to false, the list box displays items in a single column and a
vertical scroll bar appears.
Public Class Form1
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
End Sub
End Class
4. CheckedListBox
The Windows Forms
CheckedListBox control extends the ListBox control. It does almost everything
that a list box does and also can display a check mark next to items in the
list.
Public Class Form1
Dim i As Integer
Dim s As String
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles Button1.Click
s = "Checked Items:" &
ControlChars.CrLf
For i = 0 To
(CheckedListBox1.Items.Count - 1)
If
CheckedListBox1.GetItemChecked(i) = True Then
s = s & "Item "
& (i + 1).ToString & " = " &
CheckedListBox1.Items(i).ToString & ControlChars.CrLf
End If
Next
MessageBox.Show(s)
End Sub
End Class
4. ComboBox
The Windows Forms
ComboBox control is used to display data in a drop-down combo box. By default,
the ComboBox control appears in two parts: the top part is a text box that
allows the user to type a list item. The second part is a list box that
displays a list of items from which the user can select one.
Public Class Form1
Dim s As String
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ComboBox1.Items.Add(TextBox1.Text)
End Sub
Private Sub
ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim i As Integer
i = ComboBox1.SelectedIndex
s = ComboBox1.Items(i).ToString
MsgBox("You selected:" &
s)
End Sub
End Class
No comments:
Post a Comment