Draw line on picture

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis

    #1

    Draw line on picture

    I started a new thread because i cant reply on the older one.

    Thank you very much Rick for the usefull reply. But i'v got another
    question. When drawing the line, you cant see the line untill you
    release the mouse button. I want to see the line when im drawing!!
    Im using the following code:

    Private Sub Picture1_MouseD own(Button As Integer, Shift As Integer, X
    As Single, Y As Single)
    x1 = z.X
    y1 = z.Y
    lbl3 = "x1: " & x1
    lbl4 = "y1: " & y1
    With Line1
    .Visible = True
    .x1 = X
    .y1 = Y
    .x2 = X
    .y2 = Y
    Drawing = True
    End With
    End Sub

    Private Sub Picture1_MouseM ove(Button As Integer, Shift As Integer, X
    As Single, Y As Single)
    If Drawing Then
    With Line1
    .x2 = X
    .y2 = Y
    End With
    End If

    End Sub

    Private Sub Picture1_MouseU p(Button As Integer, Shift As Integer, X As
    Single, Y As Single)
    x2 = z.X
    y2 = z.Y
    'lbl5 = "x2: " & x2
    'lbl6 = "y2: " & y2
    Drawing = False
    With Line1
    Picture1.Line (.x1, .y1)-(.x2, .y2), vbGreen
    .Visible = False
    End With
    End Sub

    Can someone help me with this??


    Dennis
  • Rick Rothstein

    #2
    Re: Draw line on picture

    > Thank you very much Rick for the usefull reply. But i'v got another[color=blue]
    > question. When drawing the line, you cant see the line untill you
    > release the mouse button. I want to see the line when im drawing!!
    > Im using the following code:
    >
    > Private Sub Picture1_MouseD own(Button As Integer, Shift As Integer, X
    > As Single, Y As Single)
    > x1 = z.X
    > y1 = z.Y
    > ......<rest of code snipped>......[/color]

    I couldn't run your code because I don't know what "z" is (although it
    apparently has an X and Y property). Anyway, below is some code that
    will show the line as you draw it. It uses a Line control that is IN the
    PictureBox (use one of the two previously methods I posted to place it
    inside). You can copy/paste it exactly as is, although note that I used
    line continuations for the Sub's event declarations in order to avoid
    long line wrapping in your newsreader (you can change them back to
    single lines if you wish).

    Rick - MVP

    Dim LineIsActive As Boolean

    Private Sub Picture1_MouseD own(Button As Integer, _
    Shift As Integer, X As Single, Y As Single)
    With Line1
    If Not .Visible Then .Visible = True
    LineIsActive = True
    .X1 = X
    .Y1 = Y
    .X2 = X
    .Y2 = Y
    End With
    End Sub

    Private Sub Picture1_MouseM ove(Button As Integer, _
    Shift As Integer, X As Single, Y As Single)
    If LineIsActive Then
    With Line1
    .X2 = X
    .Y2 = Y
    End With
    End If
    End Sub

    Private Sub Picture1_MouseU p(Button As Integer, _
    Shift As Integer, X As Single, Y As Single)
    LineIsActive = False
    With Line1
    .X2 = X
    .Y2 = Y
    End With
    End Sub


    Comment

    Working...