I think you can do GDI+ drawing in just about any window in a .net windows forms project, but what do you recommend as the best built-in control for containing custom drawing? I'm going to be drawing my own x-y plots, text and images. I could use a Panel, UserControl, etc.
OnPaint. A control must provide rendering logic by overriding the OnPaint method that it inherits from Control.
Summary. User-defined controls can be created by inheriting the control class. UserControl class, or any windows forms existing control's class. The HorizontalScroll and VerticalScroll properties of the UserControl class can be used to define custom scroll bars.
PaintEventArgs in the Paint Event Handler When programming the PaintEventHandler for controls or the PrintPage for a PrintDocument, a graphics object is provided as one of the properties of PaintEventArgs or PrintPageEventArgs.
If you're just drawing the control and not hosting children, then derive from Control - VS will make you a suitable class (it calls this a 'Custom Control') with the OnDraw handler already stubbed in.
If you're hosting other controls within your control, then derive from UserControl, (VS calls this a 'User Control' and you'll get support for VS designer, so you can drag around other controls on top.
For simple non-scrolling charting I would derive from Control.
Do your GDI+ drawing in an offscreen bitmap surface, and then blit it to whatever control you need.
Your controls Paint method only needs to copy the surface to itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With