Flickering Problem in Drawing a Panel

Hi everyone,

I am trying to continuously visualize an image in a panel with C++ using Visual Studio 2008. So, I have the following code which basically reiterates the Paint event continuously.

private: System::Void panel1_Paint(System::Object^ sender,
System::Windows::Forms::PaintEventArgs^ e) {

getNewImage(img_paint); // function for getting new image
DrawImage(img_paint,pixels, pixels,1,0,false,panel1 ->Width, panel1 -> Height,e-Graphics); // function for painting the image
panel1->Invalidate(); // reiterate the Paint event

}

The problem here is that when I call Invalidate() function the panel disappears for a brief time then it gets drawn with DrawImage() function. Since getNewImage() method is very fast, I see a lot of what I believe is called as "flickering" (lots of flashes in the screen). Right now I manage this by adding Sleep(400); to the last line so that it flickers less, but this is not an optimum method as you can imagine.

When I searched the web I saw some stuff about "double buffering" but I couldn't implement them. The solutions I found are usually for C# and they cause me errors when I copy-paste to my code.

The only thing I managed to do without an error was to add "this->DoubleBuffered = true;" to the following part, but it did not change anything:

public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
this->DoubleBuffered = true;
}

I will really appreciate if you have any idea on how I can fix this problem easily.
I can't help you with this because it's too advanced for me, but you can try putting this in the General section, maybe you'll get more response there. Also, code tags might help people help you.
That is not C++, it's C++/CLI (which is a different language).
So this ain't the right forum.
Thanks guys. I managed to solve the problem. In case anyone searches this issue and comes to this page let me write the solution:

First you add this code to create your FlickerLessPanel class:,

ref class FlickerLessPanel: public System::Windows::Forms::Panel

{

public: FlickerLessPanel()

{

this->DoubleBuffered = true;

}

};

And use the following to create the panel:

private: FlickerLessPanel^ panel1;
this->panel1 = (gcnew FlickerLessPanel());

This solves the flickering problem.
Topic archived. No new replies allowed.