I am at a total loss on this issue

I have legacy C code which I have ported to C++ in a .NET Component Class that is a hybrid of managed and unmanaged code.
The Component is derived from System::Windows::Forms::UserControl and for display of an image I override WM_PAINT to draw an image using GDI between a BeginPaint and EndPaint. I also manage scrolling using Win API ShowScrollBar etc.

This all works very nicely -- the problem I am having is when I put the component control on form and then resize the form I get a nasty flicker. I have tried every combination of SetStyle in both my component class and the hosting form. I've also overriden OnPaintBackground in the hosting form and still I get flicker.

If I put a PictureBox on the form and set Docked full then load an image I do not see the same problem.
So what is it on my end I need to do to prevent the flicker?
Note: the windows painting code was written a few years ago and works in every window environement from VB to PB via ActiveX, WTL, MFC etc etc -- only in .NET have I had this problem.

OK I found a way around the flicker but of course this opened the door to other problems.
First in my control I set this->DoubleBuffered = true -- then I discontinued uses of BeginPaint and EndPaint
Now the problem ... with BeginPaint my PAINTSTRUCT rcPaint rectangle was filled with the smalled bounding rectangle needing to be updated. Much drawing optimizations are centered around this. With the Graphics Object I can find nothing that will be the equal of BeginPaint & EndPaint relative to obtaining a update rectangle.
Any help as always is appreciated.

[1628 byte] By [bxs122] at [2007-12-16]
# 1
Hopefully this will help someone else

When needing to use a PAINTSTRUCT reference with any API you can build one from the Graphics Object ...

PAINTSTRUCT ps;

ps.hdc = hDC;
::SetRect(&ps.rcPaint, pevent->ClipRectangle.Left, pevent->ClipRectangle.Top, pevent->ClipRectangle.Right, pevent->ClipRectangle.Bottom);
ps.fIncUpdate = ps.fRestore = FALSE;
ps.rgbReserved[0] = 0;

All you need is the System::Windows::Forms::PaintEventArgs ^pevent reference from a Paint Event.

The above with DoubleBuffered set to true has provided a clean optimized flicker free repaint using my old legacy code that calls for a PAINTSTRUCT reference.

bxs122 at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...