MS har en artikel om emnet her:
http://support.microsoft.com/default.aspx?scid=kb;en-us;71488Koden er lidt forældet, men jeg har lige shinet den lidt op, dette virker hos mig:
Option Explicit
Dim DrawBox As Integer '*Boolean-whether drawing Box or Line
Dim OldX As Single, OldY As Single, StartX As Single, StartY As Single '* Mouse locations
Dim SavedMode As Integer
Dim StartEvent As Boolean
Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'* Store the initial start of the line to draw.
StartX = X
StartY = Y
'* Make the last location equal the starting location
OldX = StartX
OldY = StartY
End Sub
Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'* If the button is depressed then...
If Button Then
'* Erase the previous line.
Call DrawLine(StartX, StartY, OldX, OldY)
'* Draw the new line.
Call DrawLine(StartX, StartY, X, Y)
'* Save the coordinates for the next call.
OldX = X
OldY = Y
End If
End Sub
Sub DrawLine(X1 As Single, Y1 As Single, X2 As Single, Y2 As Single)
'* Save the current mode so that you can reset it on
'* exit from this sub routine. Not needed in the sample
'* but would need it if you are not sure what the
'* DrawMode was on entry to this procedure.
SavedMode = DrawMode
'* Set to XOR
DrawMode = vbInvert
'*Draw a box or line
If DrawBox Then
Line (X1, Y1)-(X2, Y2), , B
Else
Line (X1, Y1)-(X2, Y2)
End If
'* Reset the DrawMode
DrawMode = SavedMode%
End Sub
Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'* Stop drawing lines/boxes.
StartEvent = False
End Sub
Sub Command2_Click()
'* Boolean value to determine whether to draw a line or box.
DrawBox = True
End Sub
Sub Command1_Click()
'* Boolean value to determine whether to draw a line or box.
DrawBox = False
End Sub
Sub Command3_Click()
'* Create a dotted line
Form1.DrawStyle = vbDot
End Sub
Sub Command4_Click()
'* Create a solid line.
Form1.DrawStyle = vbSolid
End Sub