实验要求
- 掌握使用Picture1_MouseDown语句/Picture1_MouseUp,Picture1_MouseMove语句和Command Dialog的实现方法。
- 实现鼠标画图程序。
- 编写实验报告。
效果
清除画布的代码(本实验没添加这个功能,留着备用)
Privte Sub Command2_Click()Picture1.Cls
End Sub
代码
Dim x1 As Integer
Dim x2 As Integer
Dim y1 As Integer
Dim y2 As Integer
Dim flag As BooleanPrivate Sub Command1_Click()On Error Resume NextCommonDialog1.CancelError = TrueCommonDialog1.DialogTitle = "颜色"CommonDialog1.ShowColorIf Err <> 32755 ThenPicture1.ForeColor = CommonDialog1.ColorEnd If
End SubPrivate Sub Form_Load()Picture1.Scale (0, 0)-(400, 400)flag = False
End SubPrivate Sub Option1_Click()Picture1.DrawWidth = 1
End SubPrivate Sub Option2_Click()Picture1.DrawWidth = 2
End SubPrivate Sub Option3_Click()Picture1.DrawWidth = 3
End SubPrivate Sub Option4_Click()Picture1.DrawWidth = 50
End SubPrivate Sub Picture1_MouseDown(button As Integer, shift As Integer, x As Single, y As Single)flag = Truex1 = xy1 = yPicture1.Line (x1, y1)-(x1 + 1, y1 + 1)
End SubPrivate Sub Picture1_MouseMove(button As Integer, shift As Integer, x As Single, y As Single)If flag = False ThenExit SubEnd IfIf flag = True Thenx2 = xy2 = yPicture1.Line (x1, y1)-(x2, y2)x1 = x2y1 = y2End IfEnd Sub
Private Sub Picture1_MouseUp(button As Integer, shift As Integer, x As Single, y As Single)flag = False
End Sub