Other Events

When we double click on BtnRed, the procedure for the click event is created. The click event is the default procedure for a button. We will now create a procedure for the double click event.

object-eventAt the top of the code view window there are two drop down boxes. The box on the left show the object, the one on the right shows the events. Select BtnRed as the object, select DoubleClick as the event.

Make sure that BtnRed is the object selected on the left, then select KeyDown from the list of events on the right. Then add the code shown below:


Private Sub BtnRed_KeyDown(ByVal sender As Object, ByVal e As _ 
    System.Windows.Forms.KeyEventArgs) Handles BtnRed.KeyDown
   Me.BackColor = Color.DarkMagenta
   Me.LblMessage.Text = e.KeyCode
End Sub

Arguments

After each procedure there are parenthesis with some code inside. The code inside the parenthesis is arguments that the procedure receives when it is invoked. In the code above an underscore is inserted after the e to split the statement onto two physical lines. (It is still one logical statement.) In the KeyDown procedure, the type of e is KeyEventArgs. In the click procedure the type of e is EventArgs. While the sender argument tells what control the event occurred for, the e argument gives us information about the event.

Experiment: Run the program and then press different keys on the keyboard. Notice the numbers that appear in the label.
Change the code so that the label displays e.Control or e.Shift. Now the label will display true or false depending on whether you hold down control or shift while you press a key on the keyboard.


INDEX, The Code View, Selecting code from list, Events, Arguments, Concatenation, Sender, Scroll Bars, Decimal Values on Scroll Bar, Picture Boxes: the Seasons, Comments, Printing, Closing
Next lesson: Functions in Visual Basic

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Events