Click here to Skip to main content
15,913,341 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
I've created a graphic object in form_paint by this code :


C#
Graphics gr = this.CreateGraphics();
gr.FillEllipse(Brushes.Yellow, 10, 30, 200, 150);


how can I make this object to treat like a control(for example a button)?;I mean user be able to move this ellipse on the form at run time.
:confused:
like powerpacks tools ,when you create the object ,you move it.
(please tell me by using path or region .... )
Posted
Updated 7-Mar-10 22:24pm
v3

1 solution

If you are doing this in the Form.Paint event (as you should), then you should not use this.CreateGraphics() - use e.Graphics instead.

You will need to handle MouseDown (capture start of move) MouseMove (Move your ellipse) and MouseUp (End of move).
Mark that you are moving in a bool in MouseDown, mark you aren't moving in MouseUp.
In MouseMove, check if you are moving, and store the coordinates of the mouse pointer. Use Invalidate() to redraw your ellipse.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900