The CheckBox control allows the user to set true/false or yes/no type
options. The user can select or deselect it. When a check box is
selected it has the value True, and when it is cleared, it holds the
value False.
Now for the coding..........
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Visible = False
End Sub
Private Sub btnMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMessage.Click
Dim str As String
str = " "
If CheckBox1.Checked = True Then
str &= CheckBox1.Text
str &= " "
End If
If CheckBox2.Checked = True Then
str &= CheckBox2.Text
str &= " "
End If
If CheckBox3.Checked = True Then
str &= CheckBox3.Text
str &= " "
End If
If CheckBox4.Checked = True Then
str &= CheckBox5.Text
str &= ""
End If
If CheckBox5.Checked = True Then
str &= TextBox1.Text
str &= " "
End If
If str <> Nothing Then
MsgBox(str + vbLf + "Thank you")
End If
End Sub
Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged
If CheckBox5.Checked = True Then
TextBox1.Visible = True
Else
TextBox1.Visible = False
End If
End Sub
End Class
Download code the here...
PAssword during extraction- soodeap
Properties of the CheckBox Control
The following are some of the commonly used properties of the CheckBox control:S.N | Property | Description |
---|---|---|
1 | Appearance | Gets or sets a value determining the appearance of the check box. |
2 | AutoCheck | Gets or sets a value indicating whether the Checked or CheckedState value and the appearance of the control automatically change when the check box is selected. |
3 | CheckAlign | Gets or sets the horizontal and vertical alignment of the check mark on the check box. |
4 | Checked | Gets or sets a value indicating whether the check box is selected. |
5 | CheckState | Gets or sets the state of a check box. |
6 | Text | Gets or sets the caption of a check box. |
7 | ThreeState | Gets or sets a value indicating whether or not a check box should allow three check states rather than two. |
Example
In this example, we create three text boxes and use the Click event of a button to display the entered text using a message box. Take the following steps:- Drag and drop three Label controls and three TextBox controls on the form.
- Change the texts on the labels to: Name, Organization and Comments respectively.
- Change the names of the text boxes to txtName, txtOrg and txtComment respectively.
- Drag and drop a button control on the form. Set its name to btnMessage and its text property to 'Send Message'.
Now for the coding..........
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Visible = False
End Sub
Private Sub btnMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMessage.Click
Dim str As String
str = " "
If CheckBox1.Checked = True Then
str &= CheckBox1.Text
str &= " "
End If
If CheckBox2.Checked = True Then
str &= CheckBox2.Text
str &= " "
End If
If CheckBox3.Checked = True Then
str &= CheckBox3.Text
str &= " "
End If
If CheckBox4.Checked = True Then
str &= CheckBox5.Text
str &= ""
End If
If CheckBox5.Checked = True Then
str &= TextBox1.Text
str &= " "
End If
If str <> Nothing Then
MsgBox(str + vbLf + "Thank you")
End If
End Sub
Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged
If CheckBox5.Checked = True Then
TextBox1.Visible = True
Else
TextBox1.Visible = False
End If
End Sub
End Class
Download code the here...
PAssword during extraction- soodeap
No comments:
Post a Comment