Title: Lab 4 Slides
1Lab 4 Slides
2In this lab
- CheckBoxes and RadioButtons
- Enabled and Visible Properties
- Multiple Events by Single Handler
- Reloading the Form
31. CheckBoxes and RadioButtons
- CheckBoxes
- Any number can be checked at a time
- RadioButtons
- Usually organized in groups and only one checked
at a time
4CheckBox Properties and Events
5CheckBox- Example
- Private Sub CheckBox1_CheckedChanged(ByVal
sender As _ System.Object, ByVal e As
System.EventArgs) Handles _ CheckBox1.CheckedChang
ed -
- If CheckBox1.Checked TrueThen
- MsgBox(Checked)
- Else
- MsgBox(Not Checked)
- End If
- End Sub
6RadioButton Properties and Events
72. Enabled and Visible Properties
83. Multiple Events by Single Handler
- The Handles keyword makes a proper connection
between the object (Button) and the event
procedure.
Private Sub Button1_Click( ByVal sender As _
system.object, ByVal e As System.EventArgs) _
Handles Button1.Click . End Sub
B1
Event (means, when Button1 is clicked , execute
this procedure)
Name Button1 Text B1
93. Multiple Events by Single Handler
- A specific event procedure can handle more than
one event. - For example, adding a second button to the form,
(automatically named Button2 ). When we
double-click it, a second event procedure is
created - Private Sub Button2_Click( ByVal sender As
System.Object, _ ByVal e As System.EventArgs)
Handles Button2.Click - Instead, the first Click procedure can be
modified to handle both buttons' Click events - Private Sub Button1_Click( ByVal sender As
System.Object, _ ByVal e As System.EventArgs)
Handles _ - Button1.Click, Button2.Click
- For most events, the object that raises the event
is passed in as the "sender" to the event
procedure. The sender parameter is typed as an
object.
103. Multiple Events by Single Handler
Code view
Design view
Private Sub LotsOfButtons(ByVal sender As _
System.Object,ByVal e As System.EventArgs)
_ Handles Button1.Click, Button2.Click,
Button3.Click, Button4.Click label1.text
sender.text is clicked End Sub
b1
b2
b3
b4
Name label1
113. Multiple Events by Single Handler
code view
Design view
Private Sub LotsOfButtons(ByVal sender As _
System.Object,ByVal e As System.EventArgs)
_ Handles Button1.Click, Button2.Click,
Button3.Click, Button4.Click label1.text
sender.text is clicked End Sub
b1
b2
b3 is clicked
b3
b4
Name label1
The sender argument provides information about
the object that raises the event
12Why do you need to know this ?
- In sheet 3, you can handle clicking all the 26
letters by single event handler. - Each time just get the sender.text to check the
letter chosen !!!!
134. Reloading the Form