Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
How can I draw a picture? I can't find anything?
Where can I start?

Thanks in advance!
Posted
Updated 27-Mar-11 13:45pm
v4
Comments
Manfred Rudolf Bihy 27-Mar-11 19:41pm    
Your question is about drawing a picture. How exactly does this correspond to you tagging this question as "WebForms"?
What are your trying to achieve?
What are your requirements?

Feel free to explain and elaborate.

1 solution

I assume you're asking not about static picture but about drawing during run-time.

You should use overridden method System.Windows.Forms.Control.OnPaint or handle event Control.OnPaint; in both case use the instance of the class System.Drawing.Graphics passed in event arguments in both cases. The control can be a System.Windows.Forms.Form or any other control, such as System.Windows.Forms.Panel. You can do it in the custom control created by subclassing System.Windows.Forms.Control (typically).

Please pay attention: the common mistake is creating an instance of the class System.Drawing.Graphics using its constructor. You should not do it (as a rule of thumb); the instance is already provided in the arguments of the methods mentioned above.

If you need to modify the graphics (with is need for animation or just to reflect changed state. In this case, you need to changes the data you use for rendering and call Control.Invalidate. To improve performance, you can used overloaded Invalidate methods with parameters (Rectangle or Region) to invalidate just the part of the control. After invalidation, WM_PAINT Windows message will be triggered, which will cause the call of your rendering method OnPaint and then your handlers of Paint event if you provide any.

—SA
 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 27-Mar-11 19:48pm    
Actually for a question that can be summed up into "I can't find anything", your solution has once again gone beyond all limits. Take my 5 and my congratulations for trying to read OP's mind. :)
Sergey Alexandrovich Kryukov 27-Mar-11 19:52pm    
Thank you very much, Manfred. Your questions to OP you posted are absolutely correct. OP is supposed to find the way to draw in the help of try to write some code before asking.
--SA
Manfred Rudolf Bihy 27-Mar-11 20:14pm    
Yes SA, usually I try do some "mind reading" myself, but this question was just a bit to general for me. :)

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