Results 1 to 4 of 4

Thread: another drawing question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    27
    i would like to be able to draw a stright line inside a picture box, like in MS paint. I have the code to draw the lines, but i can't figure out how to erase the line if the mouse moves. If you don't know what i mean, open up paint and select the straight line tool. I would like to be able to code something just like that. Here's the code i have so far:

    Option Explicit

    Private Sub picDraw_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    picDraw.CurrentX = X
    picDraw.CurrentY = Y
    End Sub

    Private Sub picDraw_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If Button = 1 Then
    picDraw.Line (X, Y)-(picDraw.CurrentX, picDraw.CurrentY), RGB(255, 0, 0)
    End If

    End Sub


    can anyone help me?

  2. #2
    Guest
    Like this? A straight line:

    Code:
    Public A, B As Integer
    
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then Picture1.Line (A, B)-(X, Y)
        A = X: B = Y
    End Sub
    
    
    Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then Picture1.Line (X, Y)-(X + 15, Y + 15)
    End Sub
    And for erasing:

    Code:
    Picture1.Cls
    Is that what you wanted?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    27
    that code draws a line, but not straight.i meant each time the mouse moves, erase the old line and draw the new one. If you want to see what i mean, load up paint and use the straight line tool.

  4. #4
    Addicted Member Dim A's Avatar
    Join Date
    Jul 2000
    Posts
    201
    Originally posted by gfreeman1
    that code draws a line, but not straight.i meant each time the mouse moves, erase the old line and draw the new one. If you want to see what i mean, load up paint and use the straight line tool.
    Most programs use XOR to show where lines are going to be placed so that the data in the image isn't destroyed only temporarily inverted.

    I checked paint, it doesn't do this. I would suggest a second picture window, possibly hidden or off screen, that stores the current fixed image. The main display will just be a scratch buffer that's just a combination of the current tool preview and the hidden buffer.

    Once the line is placed, you update the hidden buffer, and the main display, and await the next tool command.

    XOR might be easier if you're still working on this at all... I mean it has been close to a year.

    - Dim A

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width