如何在vb6中的图片框中绘图

时间:2013-04-02 18:23:49

标签: vb6 drawing picturebox

我已经使用了大量的网站,但没有一个工作,所以我希望我能得到一个正确的答案

我试过这可以告诉我它有什么问题:

    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

我已经关闭私人子Picture1_MouseMove,Mousedown()位,因为我急于完成

2 个答案:

答案 0 :(得分:1)

这一行将绘制一条线,与kurniliya的解决方案略有不同,该解决方案绘制点

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

答案 1 :(得分:0)

您使用PictureBox方法在Line控件上绘制一行:

  

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

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

关于它没有太多可说的,How do you draw a line dynamically in vb6?

已经涵盖了它

你似乎在编写事件处理程序方面遇到了麻烦。如果您不知道/记住签名,IDE总是在那里提供帮助。查看Assigning Code to a Control to Respond to an Event in 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