I have a problem with flickering for a lot of buttoncontrols in a panel.

I have put a panel on the form that holds 200 buttoncontrols. When switching from one panel to this panel, all 200 buttoncontrols flickers for about 2 seconds.

I have red that if setting DoubleBuffered = true; for the Form, this could be the solution but that does not work.

What I think I have understand from when googlig around is that something has to be done with the container that holds the flickering control wich in this case is panel1 but I cant get examples of what I need to do.
This is what I think a solution is about but I am not sure ?

I would be very happy for any kind of help as this has been a problem through my whole project.

Thank you!

What I have on the form is a panel with 200 buttoncontrols that "flickers".
For example when I minimize the formwindow and maximize the formwindow again, all 200 buttoncontrols will flicker for 2 seconds.

I think I in somehow need to set the doublebuffer for the panel1 that holds the buttoncontrols but dont know how to do this.


How will I prevent this "flickering" ?

I can't help with your settings. But I have a couple questions that may help.

Obviously, I don't know your machine's performance specs, but it could be an issue with your machine's performance. Have you tried running the exe on a different machine to see what happens? This could help you determine if it's a program or hardware related issue.

Do you have any onEntry, onFocus, or similar type events defined for panel1? If so, what do they do? Have you looked through those?

Thank you for answer.
I dont think my computer is the problem in this case. I have:
AMD Athlon(tm) 64 X2 Dual Core Processor 4200+
2.2 GHz, 3.50 GB of RAM

I have not used any events as onEntry, onFocus for Panel1. I have just put all 200 buttoncontrols inside Panel1.

I can't help with your settings. But I have a couple questions that may help.

Obviously, I don't know your machine's performance specs, but it could be an issue with your machine's performance. Have you tried running the exe on a different machine to see what happens? This could help you determine if it's a program or hardware related issue.

Do you have any onEntry, onFocus, or similar type events defined for panel1? If so, what do they do? Have you looked through those?

I have googled around but seems to have problem find a straight example.
Something that I have found is that I think I need to create an own panel class where I could set the doublebuffer and style like below.

I have tried to convert a C# example but this does not compile.
syntax error : 'public'
syntax error : ':'
unexpected token(s) preceding ':'; skipping apparent function body

I wonder what could be wrong with this code ?

public class DoubleBufferPanel^ : Panel
{
	public DoubleBufferPanel()
	{
		// Set the value of the double-buffering style bits to true.
		this->SetStyle(ControlStyles::DoubleBuffer | ControlStyles::UserPaint | 
                   ControlStyles::AllPaintingInWmPaint, true);
		this->UpdateStyles();
	}
}

I am trying to inherit a panel because when I do that, it would be possible to set this panel to have these properties and doublebuffer.

I am not sure if I am doing this right. The first thing is to create the panel class and then use this class for the declarations below but this does not compile. I am quite lost of how I will be able to declare all this.
I am exchanging the outlines lines to the line below but dont know if I am on the right track here ?

Thank you...

public: class Panel^ DoubleBufferPanel()
		{
			// Set the value of the double-buffering style bits to true.
			this->SetStyle(ControlStyles::DoubleBuffer | ControlStyles::UserPaint | ControlStyles::AllPaintingInWmPaint, true);
			this->UpdateStyles();			

			return DoubleBufferPanel();
		}


          //private: System::Windows::Forms::Panel^  panel1;
	DoubleBufferPanel^ panel1;

        //this->panel1 = (gcnew System::Windows::Forms::Panel());
	panel1 = gcnew DoubleBufferPanel();

I'm 100% newb with Windows Forms so I can't help you with that, but I can say that your class definition is not set up correctly.

General form of a C++ class definition:

[b]class[/b] [i]className[/i] [B]:[/B] [B]inheritanceType[/B] [I]inheritedClassName[/I]
[B]{[/B]
[b]private:[/b] /* optional, classes default to private access level */
/* private members, usually variables */

[B]protected:[/B]
/* "private" members that must be accessible from derived classes */

[B]public:[/B]
/*externally accessible methods/properties */

[B]};[/B]

For your situation, className would be DoubleBufferPanel, inheritanceType would be public, and inheritedClassName (I suspect) would be Panel. But, like I said, I don't know Windows Forms. Panel is probably not the correct name for the class you want to inherit from. You will have to look that up in your documentation, on MSDN, or in some other similar source.

Thank you for your answer, I understand that you are a newbie then.
I think my first goal is to declare this class properly. I have tried to follow your example and the class should be as you say, Panel.

However this code does not compile. I would be happy to learn how to declare this properly.
Compile errors:
syntax error : 'public'
syntax error : '{'
unexpected token(s) preceding '{'; skipping apparent function body

class DoubleBufferPanel public Panel^
		{
			// Set the value of the double-buffering style bits to true.
			this->SetStyle(ControlStyles::DoubleBuffer | ControlStyles::UserPaint | ControlStyles::AllPaintingInWmPaint, true);
			this->UpdateStyles();			

			return DoubleBufferPanel();
		};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.