Changes

Jump to: navigation, search

Understanding Visual Basic Events

1,401 bytes added, 17:53, 17 July 2007
Wiring Up Events in Visual Studio
Clicking the Button should close the application as specified in the ''Click()'' event procedure.
 
== Setting Up a Visual Basic Timer Event ==
 
At the beginning of this chapter we mentioned that objects can trigger their own events. So far we have only looked at events triggered by user interaction with the application's user interface. We will now look at configuring the ''Timer'' object to trigger its own events. The first step is to add a ''Timer'' object to our application. First, display the Toolbox if it is not already visible, unfold the ''Components'' section of the Toolbox list and scroll down until you find the ''Timer'' object. To add a ''Timer'' to the application simply double click on it. Because the Timer is not a visible object it appears in a special area beneath the Form as shown in the following figure:
 
[[Image:Exampl.jpg]]
 
With the ''Timer'' object selected, use the ''Properties'' panel to change the ''Enabled'' property to ''True'' and the ''Interval'' property to ''10000''. Next double click on the ''Timer'' object to edit the event procedure. The ''Timer'' object has a single event, the ''Tick'' event, which is triggered each time the timer interval elapses. We are going to write code to set the myLabel control to display ''Your time is up'' when the ''Tick'' event triggers:
 
<pre>
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Timer1.Tick
 
myLabel.Text = "Time is up"
 
End Sub
</pre>

Navigation menu