<
Previous
|
Next
|
VB Tutorial
|
Contents
>
VB Event Procedure
When an object in Visual Basic recognizes that an event has occurred, it automatically invokes the event procedure using the name corresponding to the event.
1. Make a new project and drag and drop a label into the form
2. Change the name property of the label into lblXY
3. Change autosize property of the label into true
4. In the declaration section, type the following code:
Option Explicit Private increment As Long Private lastX As Single Private lastY As Single
5. Type this procedure in Form_MouseDown and Form_MouseMove event procedures.
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) increment = increment + 1 If increment Mod 2 = 0 Then Me.Line (lastX, lastY)-(X, Y) Else lastX = X lastY = Y End If End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) lblXY.Caption = "(X, Y)= " & X & " , " & Y Me.PSet (X, Y), vbBlue End Sub
6. Run the program and now you can draw in the form using your mouse
<
Previous
|
Next
|
VB Tutorial
|
Contents
>
Rate this tutorial or give your comments about this tutorial