求用vb编一段简单的用鼠标拖动画直线的程序!

来源:百度知道 编辑:UC知道 时间:2024/05/17 22:24:20
就是类似与vb中画直线的控件的那种画图程序,在点按下鼠标左键的同时开始画线,抬起鼠标左键的地方是终点,做一条线,线的颜色要可以自己调,不过在拖动鼠标时可以看到划线的过程以便调整,我自己编的时候,因为拖到哪里就会把线画到哪里,不能删掉原来的线,所以一拖动鼠标就会出现好多线,有人说要把先前拖出来的线和背景色异或一下之类的,我不知道该怎么做,谁能帮帮我!多谢!
回一楼沙发的那位,不好意思,因为还有其他的背景图,所以不能用Form1.Cls语句吧?

Dim xpos As Single, ypos As Single
Private Sub Form_Load()
Me.MousePointer = 2
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'若要自己调颜色 工程-部件-microsoft common dialog control 6.0打钩-确定,添加一个commondialog控件并去掉下面两句的注释符
'If Button = 2 Then Me.CommonDialog1.ShowColor
'Me.ForeColor = Me.CommonDialog1.Color
Me.AutoRedraw = False
xpos = X: ypos = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Refresh
If Button = 1 Then Line (xpos, ypos)-(X, Y)
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.AutoRedraw = True
Line (xpos, ypos)-(X, Y)
End Sub

Public WithEvents Liness As Line
Public Counts As Integer
Public isCan As Boolean
Private Sub Form_Load()
Counts = 0
isCan = False
End Sub

Private Sub Form