Download presentation
Presentation is loading. Please wait.
Published byLoren Wilkerson Modified over 6 years ago
1
Do Now: What are the three steps to writing a Visual Basic Program?
1. Create the interface 2. Write the code 3. Test data
2
3.2 Visual Basic Events An Event Procedure Walkthrough
Properties and Event Procedures of the Form The Header of an Event Procedure
3
Event An event is an action, such as the user clicking on a button
Usually, nothing happens in a Visual Basic program until the user does something and generates an event. What happens is determined by statements.
4
controlName.property = setting
Code A set of statements that carry out tasks Sample Statements txtBox.ForeColor = Color.Red txtBox.Visible = True txtBox.Text = “Hello World” General Form: controlName.property = setting
5
Structure of an Event Procedure
Private Sub objectName_event(..)Handles objectName.event statements End Sub (...) is filled automatically with (ByVal sender As System.Object, ByVal e As System.EventArgs) Header
6
Create the following Sample Form
txtFirst txtSecond btnRed
7
Create an Outline for an Event Procedure; i.e. header and End Sub
1. Double-click on a control or 2. Use the Class Name and Method Name boxes. (We primarily use the first method.)
8
Double Click on txtFirst
Sample Form Double Click on txtFirst txtFirst txtSecond btnRed
9
Code for Walkthrough Public Class frmDemo
Private Sub txtFirst_TextChanged()Handles txtFirst.TextChanged txtFirst.ForeColor = Color.Blue End Sub End Class
10
Automatically pops up to give the programmer help.
IntelliSense Automatically pops up to give the programmer help.
11
Double-click on btnRed
Sample Form Double-click on btnRed txtFirst txtSecond btnRed
12
Code for Walkthrough Public Class frmDemo
Private Sub txtFirst_TextChanged()Handles txtFirst.TextChanged txtFirst.ForeColor = Color.Blue End Sub Private Sub btnRed_Click(...)Handles btnRed.Click txtFirst.ForeColor = Color.Red End Class
13
Event Procedure txtFirst.Leave
Select txtFirst from Class Name box drop-down list. Select Leave from Method Name box drop-down list.
14
Code for Walkthrough Private Sub txtFirst_Leave(...) Handles txtFirst.Leave txtFirst.ForeColor = Color.Black End Sub Private Sub txtFirst_TextChanged()Handles txtFirst.TextChanged txtFirst.ForeColor = Color.Blue Private Sub btnRed_Click(...) Handles btnRed.Click txtFirst.ForeColor = Color.Red
15
Handling Multiple Events
Event procedure can be invoked by two events. Private Sub Button_Click()Handles btnRed.Click, txtSecond.Leave txtFirst.ForeColor = Color.Red End Sub
16
JUST SOME NOTES A font's
name, style, and size properties cannot be altered in code with statements of the txtBox.Font.Name = "Courier New" txtBox.Font.Bold = True txtBox.Font.Size = 16 If you want to know the settings, you can display them using lines like these: 1stBox.Items.Add(txtBox.Font.Name) 1stBox.Items.Add(txtBox.Font.Bold) 1stBox.Items.Add(txtBox.Font.Size)
17
More Notes The following won't work: frmDemo.Text = "Demonstration"
The form is referred to by the keyword Me. Me.Text = "Demonstration"
18
2 EXAMPLES: The form contains four square buttons arranged in a rectangular array. Each button has the caption "Push Me." When the user clicks on a button, the button disappears and the other three become or remain visible.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.