Live Chat Icon For mobile
Live Chat Icon

How can I draw without handling a paint message

Platform: WinForms| Category: Drawing Tips

To draw on any hwnd, you need to get a Graphics object from that hwnd. Once you have the Graphics object, you can then use its methods to draw. Of course, since this drawing is not done in the Paint handler, it will not be automatically refreshed when the control is redrawn for any reason.

	Graphics g = Graphics.FromHwnd(this.Handle);
	SolidBrush brush = new SolidBrush(Color.Red);
	Rectangle rectangle = new Rectangle(25, 25, 100, 100);
	g.FillRectangle(brush, rectangle);

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.