|
-
Jan 9th, 2007, 03:19 PM
#1
[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:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim ptfs() As PointF = { _
New PointF(150, 25), _
New PointF(185, 10), _
New PointF(200, 50), _
New PointF(160, 30) _
}
e.Graphics.DrawBezier(Pens.Black, _
ptfs(0), ptfs(1), ptfs(2), ptfs(3))
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
-
Jan 9th, 2007, 03:25 PM
#2
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.
-
Jan 9th, 2007, 03:53 PM
#3
Re: [2005] Drawing with mousebutton.
 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
-
Jan 9th, 2007, 03:56 PM
#4
Re: [2005] Drawing with mousebutton.
It disappears because of this line:
VB Code:
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
-
Jan 9th, 2007, 04:06 PM
#5
Re: [2005] Drawing with mousebutton.
 Originally Posted by Atheist
It disappears because of this line:
VB Code:
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
-
Jan 9th, 2007, 04:10 PM
#6
Re: [2005] Drawing with mousebutton.
hmm I dont really know...have you looked into DirectX? I think you might find something there.
-
Jan 9th, 2007, 04:13 PM
#7
Re: [2005] Drawing with mousebutton.
 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
-
Jan 9th, 2007, 05:14 PM
#8
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|