Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi,

How to draw movable and re-sizable shapes( Line, Circle) in VC++ forms.
Posted
Comments
Sergey Alexandrovich Kryukov 20-Aug-14 11:16am    
Why MFC is tagged then?
—SA

1 solution

You have to program the whole system for doing so, using just one control. It could be a custom control, or, say, Panel.
The word "shapes" (not "shape") makes it a pretty complex thing. You would need to develop the type hierarchy, rendering, all those graphical elements showing the shape's extents, to change the shape by selecting a small rectangular marker and moving it (or something like that).

But the base of it is pretty simple. You should put all graphical data in some data model. You need to have rendering of this model onto the rendered control either by overriding its method OnPaint or handling its event Paint. You should use the instance of the System.Drawing.Graphics passed to you in these methods' parameter (it's a usual mistake of the beginners to create the Paint instance, which would be wrong in this case). And, to do any move or transformation, you need to use Control.Invalidate, to trigger the redrawing.

Please see my past answers for further detail:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

—SA
 
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