JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Handling Picture Box Events (and Creating Image Maps)

The New Products Department is on the phone; they want you to design a program to welcome new employees to the company. The program should display a picture of the main plant, and when the new employee clicks part of that image, "it should sort of zoom in on it." Can you do that in Visual Basic?

You can if you handle mouse events for the picture box and respond accordingly. For example, the PictureBoxes example on the CD-ROM handles MouseDown events by displaying the location where the mouse went down in a text box:

Private Sub PictureBox1_MouseDown(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.MouseEventArgs) Handles _
    PictureBox1.MouseDown
    TextBox1.Text = "You clicked at " & e.X & ", " & e.Y
End Sub

You can see the results of this code in Figure 7.18, where I've clicked the picture box.

Click To expand
Figure 7.18: Creating an image map with a picture box.

Related solution:

Found on page:

Handling Mouse Events

199

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor