CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Drawing square by mouse

    Hi to everyone who cared about my message.

    I want to know how to delete lines in my drawing program.

    Since I try to draw line, I do like this:
    1. As mouse down, it is the start x and y point.
    2. As mouse move, draw a line to the point that the mouse is located.

    Here is a problem, As long as mouse is moving or until mouse-up, lines I have created should go away. The program just leaves the lines there. It should be just like MS paint.
    If you understood my english, and know a good idea for this.
    Please help me.




  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Drawing square by mouse

    Try using the Invert Pen to create a RubberBand Effect, eg.

    private oX as Integer
    private oY as Integer
    private lX as Integer
    private lY as Integer

    private Sub Form_Load()
    Picture1.ScaleMode = vbPixels
    End Sub

    private Sub Picture1_MouseDown(Button as Integer, Shift as Integer, X as Single, Y as Single)
    If Button = vbLeftButton then
    oX = X
    oY = Y
    Picture1.DrawMode = vbInvert
    End If
    End Sub

    private Sub Picture1_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
    If Button = vbLeftButton then
    Picture1.Line (oX, oY)-step(lX - oX, lY - oY), , B
    Picture1.Line (oX, oY)-step(X - oX, Y - oY), , B
    End If
    lX = X
    lY = Y
    End Sub

    private Sub Picture1_MouseUp(Button as Integer, Shift as Integer, X as Single, Y as Single)
    Picture1.Line (oX, oY)-step(lX - oX, lY - oY), , B
    Picture1.DrawMode = vbCopyPen
    Picture1.Line (oX, oY)-step(X - oX, Y - oY), , B
    End Sub





    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  3. #3
    Guest

    Re: Drawing square by mouse

    Thanks to Aaron. I ll try that way.



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

Featured