1

我为此使用了很多网站,但没有一个有效,所以我希望我能得到正确的答案

我试过这个,谁能告诉我它有什么问题:

    Private sub Picture1_mouseDown
    x = picture1.currentx
    y = picture1.currenty
    End sub

    Private sub Picture1_MouseMove
    If button = 1 then
    line (picture1.currentx,picture1.currenty)-(x,y), _
    QBColor(0)
    End if 
    End sub

我已经剪掉了 Private sub Picture1_MouseMove,Mousedown() 位,因为我急于完成

4

2 回答 2

2

这将画一条线,与 kurnilia 画点的解决方案略有不同

Option Explicit

Private lastX As Single
Private lastY As Single

Private Sub Form_Load()
    ' no need to set this every time we move the mouse inside Picture1
    Picture1.DrawWidth = 5
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        Picture1.Line (lastX, lastY)-(X, Y), vbBlue
    End If
    lastX = X
    lastY = Y
End Sub
于 2013-04-03T21:58:55.867 回答
1

您使用它的方法在PictureBox控件上画一条线:Line

子线(标志为整数,X1 为单,Y1 为单,X2 为单,Y2 为单,颜色为长)

Member of VB.PictureBox
Draws lines and rectangles on an object.

没什么好说的,在vb6中如何动态画线已经介绍过了。

不过,您似乎在编写事件处理程序时遇到了麻烦。如果您不知道/不记得签名,IDE 随时为您提供帮助。查看将代码分配给控件以响应 VB6教程中的事件。

有代码可以帮助您开始绘图。Picture1PictureBox控制。当您将鼠标移到图片框上并按住鼠标左键时,将绘制蓝线。

Option Explicit

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        Picture1.DrawWidth = 5
        Picture1.Line (X, Y)-(X, Y), vbBlue
    End If
End Sub
于 2013-04-03T07:40:32.690 回答