Part II


The other argument, e, contains information you need to process the event. The information available depends on the type of event that was raised. Since the members available through the “e” argument depend on the kind of action that raised the event, it is important (particularly for VB 6 programmers who are learning VB.NET) to use an event that provides the information you’re interested in. If you need mouse-type information, you must use a mouse-type event, and so on. For a sample of the difference, the next illustration shows you the members available using the e argument with the Click event versus the MouseClick event.

——–
Click Here to display the illustration
Click the Back button on your browser to return
——–

For a more practical example of this, I’d like to thank (again … for the umpteenth time) frequent contributor Dr. Peter Ingerman for suggesting this topic with a question he sent to me in an email. Dr. Ingerman asked, “What I’m trying to do is to determine whether the user clicked on the PictureBox in the upper third of the picture, the middle third of the picture, or the bottom third of the picture.”

Here’s the code that does the trick!

Private Sub PictureBox1_MouseDown( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles PictureBox1.MouseDown
Dim myPicBox As PictureBox = sender
Select Case e.Y / myPicBox.Height
Case Is > 2 / 3
Debug.WriteLine(“It’s in the bottom third”)
Case Is > 1 / 3
Debug.WriteLine(“It’s in the middle third”)
Case Else
Debug.WriteLine(“It’s in the top third”)
End Select
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s