本例演示一个简单的绘图应用程序。当任意鼠标按钮按下并拖动时,MouseDown 事件过程和一个相关的 MouseMove 事件过程协同工作以启动绘图。 MouseUp 事件过程禁止绘图。 要尝试这个例子,可将代码粘贴到一个窗体的声明部分,然后按 F5 键,单击窗体并在鼠标按钮按下时移动鼠标。
Dim PaintNow As Boolean
Private Sub Form_MouseDown (Button As Integer, Shift As Integer, X As
Single, Y As Single)
PaintNow = True ' 启动绘图。
End Sub
Private Sub Form_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
PaintNow = False ' 禁止绘图。
End Sub
Private Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
If PaintNow Then
PSet (X, Y) ' 画一个点。
End If
End Sub
Private Sub Form_Load ()
DrawWidth = 10 ' 使用更宽的刷子。
ForeColor = RGB(0, 0, 255) ' 设置绘图颜色。
End Sub