在PicuureBox 中的图片上用鼠标画直线 当鼠标按下的时候选定起始点 移动鼠标 然后再次按下鼠标的时候结束画图?
谢谢~

解决方案 »

  1.   

    Dim oldx As Single
    Dim oldy As Single
    Dim i As Integer
    Private Sub Form_Load()
        i = 0
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        End
    End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        i = i + 1
        If i Mod 2 = 0 Then
            Picture1.Line (oldx, oldy)-(X, Y)
        Else
            oldx = X
            oldy = Y
            Picture1.PSet (X, Y)
        End If
    End Sub
      

  2.   

    MouseDown
    MouseMOve
    Mouseup
    三个事件可以实现绘图。
      

  3.   

    Option Explicit
    Dim X1 As Long
    Dim X2 As Long
    Dim Y1 As Long
    Dim Y2 As Long
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button <> vbLeftButton Then Exit Sub
        X1 = X
        Y1 = Y
    End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button <> vbLeftButton Then Exit Sub
        X2 = X
        Y2 = Y
        Picture1.Line (X1, Y1)-(X2, Y2)
    End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button <> vbLeftButton Then Exit Sub
        X2 = X
        Y2 = Y
        Picture1.Line (X1, Y1)-(X2, Y2)
    End Sub
      

  4.   

    把MouseMove去掉就是了,刻意写的
      

  5.   

    Dim oldx As Single
    Dim oldy As Single
    Dim bg As Boolean
    Private Sub Form_Load()
        Me.AutoRedraw = True  '这个属性对照From1的属性窗里里有说明
        bg = True
    End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then       '当鼠标左建按下时发生
            If bg = False Then
                Picture1.Line (oldx, oldy)-(X, Y)
            End If
            oldx = X
            oldy = Y
            bg = False
        End If
    End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        bg = True
    End Sub