Windows Develop Bookmark and Share   
 index > Windows Forms General > GDI+
 

GDI+

when ever i use something like:

System::Drawing::Pen ^pen= gcnew System::Drawing::Pen(System::Drawing::Color::Black, 100);

grfx = System::Drawing::Graphics::FromHwnd(this->Handle);

grfx->DrawLine(pen, 1, 1, 1 ,20);

Threading::Thread::Sleep(1000);

grfx->Clear(System::Drawing::Color::White);

it draws ok. but when ever i move the app offscreen the line that i just drawn, dissapears. how do i fix this?

thanks in advanced, Dan.

help-linux  Wednesday, February 14, 2007 3:42 PM

The GDI+ framework doesn't automatically repaint the clipping region when a WM_PAINT message comes into the message loop -- you need to handle this yourself. If it's just a couple of lines, you can simply repaint everytime you get a paint request; if it's a more complex structure you'll need an underlying model of some sort that keeps track of things.

There is also a WM_ERASEBKGND message that controls respond to to repaint thier background to match the current theme; you can set a control style to have these messages filtered.

HTH

Alan Robbins  Wednesday, February 14, 2007 4:19 PM

You should ideally not use Graphics::FromHwnd, but should rather place your drawing code in the OnPaint override or the Paint event. These will pass you a PaintEventArgs that contains a graphics surface to draw to. You will also then not need the Thread::Sleep either.

Sean Hederman  Wednesday, February 14, 2007 8:30 PM
my only guess is to, keep re-drawing it.
help-linux  Wednesday, February 14, 2007 3:53 PM

The GDI+ framework doesn't automatically repaint the clipping region when a WM_PAINT message comes into the message loop -- you need to handle this yourself. If it's just a couple of lines, you can simply repaint everytime you get a paint request; if it's a more complex structure you'll need an underlying model of some sort that keeps track of things.

There is also a WM_ERASEBKGND message that controls respond to to repaint thier background to match the current theme; you can set a control style to have these messages filtered.

HTH

Alan Robbins  Wednesday, February 14, 2007 4:19 PM

You should ideally not use Graphics::FromHwnd, but should rather place your drawing code in the OnPaint override or the Paint event. These will pass you a PaintEventArgs that contains a graphics surface to draw to. You will also then not need the Thread::Sleep either.

Sean Hederman  Wednesday, February 14, 2007 8:30 PM
Thanks for the help. i never really understood how it works. now it seems alot more clear :)
help-linux  Wednesday, February 14, 2007 10:26 PM

You can use google to search for other answers

Custom Search

More Threads

• Vertical & Horizontal scroll details of ListView
• problem with tabpages in tabstrip
• Determine if a Form has been created...
• ListView column order confusion
• Windows Form not updating the label text .. Please Help
• Help.ShowHelp using several chm files
• Alt-V key detecting
• How to develop custom button control using SendMessage(...)?
• Word 2003
• tablelayoutpanel flicker / performance