Chapter 3 (ctd) Section 3.2 EVENTS
Three stages in the creation of a Visual Basic program: zCreate the interface yie, choose & create the objects zSet the objects’ properties yuse the properties window of each object zCreate the code to respond to a user’s interaction with the objects zExamplesExamples
Responding to events zWe can write code to respond to user’s actions. zA user’s actions are called events. zEvent-driven programs are ones in which specific groups (or modules) of statements are executed on the basis of what the user does. zIn this section, we focus on statements that respond to a user’s actions by changing the properties of objects.
Basic features of an event procedure zFirst, invoke the window of an object by double-clicking on the object. double-clicking zFormat: Private Sub ObjectName_Event() Visual Basic code goes here End Sub Private Sub ObjectName_Event() Visual Basic code goes here End Sub
ExampleExample from text, pp zNote the interface for the example: ObjectProperty Setting WalkthroughCaption Demonstration txtPhraseText (blank) cmdBoldCaption Make Phrase Bold zLet’s create it
zThe text box txtPhrase has 2 events written for it: ytxtPhrase_LostFocus ytxtPhrase_GotFocus zThe command button cmdButton has 1 event written for it: ycmdBold_Click
Lab Assignment (Lab2) zCreate the forms, objects & events for p. 69: 38, 39, 40 Due today!
Homework Assignment (HW2) zDue next Tuesday zPage 70, #46, #47.