Results 1 to 8 of 8

Thread: [2005] Drawing with mousebutton.

  1. #1

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    [2005] Drawing with mousebutton.

    Hi All,

    1) question:

    I'm trying to draw some lines, rectangles ore ellipses with the left mousebutton, but I can't make it to work with the mousedown event.

    This is the code I use for the Form_paint event and it's working fine.

    VB Code:
    1. Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    2.         Dim ptfs() As PointF = { _
    3.                            New PointF(150, 25), _
    4.                            New PointF(185, 10), _
    5.                            New PointF(200, 50), _
    6.                            New PointF(160, 30) _
    7.                        }
    8.         e.Graphics.DrawBezier(Pens.Black, _
    9.              ptfs(0), ptfs(1), ptfs(2), ptfs(3))
    10.     End Sub

    How can I use this code to draw a line, rectangle or something drawing with
    the mouse.

    2) question

    After I'm drawing something I want to resize the drawing, like for example Autocad does. For example to change te rectangles size after drawing.

    Thanks in advance,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Drawing with mousebutton.

    Take a look at this link http://www.vbforums.com/showthread.p...&highlight=GDI

    I've posted some code that lets you click and hold the mousekey to draw and resize a rectangle. Remove the For Next loop in the MouseUp subroutine though, it was for selecting the controls inside the rectangle.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2005] Drawing with mousebutton.

    Quote Originally Posted by Atheist
    Take a look at this link http://www.vbforums.com/showthread.p...&highlight=GDI

    I've posted some code that lets you click and hold the mousekey to draw and resize a rectangle. Remove the For Next loop in the MouseUp subroutine though, it was for selecting the controls inside the rectangle.
    Hi Atheist,

    Your code is working in that way that it draws a rectangle, so far so good. But if you com loose the mousekey then the drawing disappears.

    Is there a way to draw that rectangle for real after you loose the mousekey and that you can click it again to resize it.

    Thanks,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Drawing with mousebutton.

    It disappears because of this line:

    VB Code:
    1. a.Graphics.Clear(Me.BackColor)

    You can not resize a drawn rectangle using GDI+, simply because drawn things are no objects, they are just drawings on the screen. I would say the application doesnt even know theyre there
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2005] Drawing with mousebutton.

    Quote Originally Posted by Atheist
    It disappears because of this line:

    VB Code:
    1. a.Graphics.Clear(Me.BackColor)

    You can not resize a drawn rectangle using GDI+, simply because drawn things are no objects, they are just drawings on the screen. I would say the application doesnt even know theyre there
    Hi,

    What do I have to do to create a drawing that I can resize again.

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Drawing with mousebutton.

    hmm I dont really know...have you looked into DirectX? I think you might find something there.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2005] Drawing with mousebutton.

    Quote Originally Posted by Atheist
    hmm I dont really know...have you looked into DirectX? I think you might find something there.
    Hi,

    No I didn't looked into DirectX, but I'll try.

    Thanks,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  8. #8
    Addicted Member
    Join Date
    Sep 2004
    Location
    UK
    Posts
    129

    Re: [2005] Drawing with mousebutton.

    Hi, you wont need to use DirectX, it offers nothing of much help I’m afraid.

    GDI+ will not diretly allow you to select and resize an object, but you can and have to use it to actually perform this task.

    Once you draw an object you must persist the object in say a collection. Once you have that you need to hit test the collection when you move the mouse. Point in rectangle springs to mind.
    When you have a hit you then need to decide what to do, add some selection grips say. Next you have to actually size the object, again this all needs to be done, track the mouse as you resize redrawing the shape as you go.
    This all is not a trivial task but very doable.

    Bob Powells site should get you started:

    http://www.bobpowell.net/

    Julian

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