【问题标题】:How to draw in a picturebox in vb6如何在vb6中画一个图片框
【发布时间】:2013-03-24 04:23:42
【问题描述】:

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

我试过了,谁能告诉我有什么问题:

    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() 位,因为我急于完成

【问题讨论】:

    标签: vb6 drawing picturebox


    【解决方案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
    

    【讨论】:

      【解决方案2】:

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

      子线(标记为整数,X1 为单,Y1 为单,X2 为单,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
      

      【讨论】:

      • @Swynco.Inc, Option Explicit 可能是您从这个答案中获得的最重要的东西,以便您将来在 VB6 中进行所有编码
      • 这在一定程度上有效。它不画一条线,而是一个点,并且非常类似于Picture1.PSet (X, Y),增加了对点颜色的控制。 @Swynco.Inc 正朝着画线的方向前进 - 或者至少是连接点,正如您从 MouseMove 处理程序中看到的那样。在快速移动鼠标的同时尝试这段代码,你会发现它是在绘制点,而不是线。
      猜你喜欢
      • 1970-01-01
      • 2023-03-03
      • 2018-03-15
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多