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

就是类似与vb中画直线的控件的那种画图程序,在点按下鼠标左键的同时开始画线,抬起鼠标左键的地方是终点,做一条线,线的颜色要可以自己调,不过在拖动鼠标时可以看到划线的过程以... 就是类似与vb中画直线的控件的那种画图程序,在点按下鼠标左键的同时开始画线,抬起鼠标左键的地方是终点,做一条线,线的颜色要可以自己调,不过在拖动鼠标时可以看到划线的过程以便调整,我自己编的时候,因为拖到哪里就会把线画到哪里,不能删掉原来的线,所以一拖动鼠标就会出现好多线,有人说要把先前拖出来的线和背景色异或一下之类的,我不知道该怎么做,谁能帮帮我!多谢!
回一楼沙发的那位,不好意思,因为还有其他的背景图,所以不能用Form1.Cls语句吧?
展开
 我来答
zhenghanxi
2008-05-17 · TA获得超过422个赞
知道小有建树答主
回答量:268
采纳率:0%
帮助的人:254万
展开全部
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
zhanghanhx
2008-05-19 · 超过82用户采纳过TA的回答
知道答主
回答量:230
采纳率:0%
帮助的人:249万
展开全部
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_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Set Liness = Controls.Add("vb.line", "Liness" & Counts)
isCan = True
Counts = Count + 1
Liness.x1 = X
Liness.y1 = Y
End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 And isCan = True Then
Liness.Visible = True

Liness.X2 = X
Liness.Y2 = Y

End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
isCan = False
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式