I have a Panel that holds 200 buttoncontrols. If I for example minimize the Formwindow and maximize the window again,
panel1 that holds the 200 buttoncontrols makes the 200 buttoncontrols to "flicker" for about 2 seconds.

I beleive I have set up code for panel1 that have Doublebuffer = true;
(I run this on computer: 2.2 Ghz Dual core)

I dont know how to make this work correctly because the whole application really flickers all the time ?
Below I have put all declarations that has with panel1 to do to see if it is possible to find the problem.

//panel1 declaration
public ref class DoubleBufferPanel : public Panel  
{  
	public: DoubleBufferPanel(void)    
	{        
	    this->SetStyle(ControlStyles::DoubleBuffer | 
             ControlStyles::UserPaint  | 
             ControlStyles::AllPaintingInWmPaint, true);         
	    this->SetStyle(ControlStyles::DoubleBuffer, true);        
	    this->UpdateStyles();    
	}  
};


	//private: System::Windows::Forms::Panel^  panel1;
	DoubleBufferPanel^ panel1; //Exchange above line to this line ?


//this->panel1 = (gcnew System::Windows::Forms::Panel());
panel1 = gcnew DoubleBufferPanel(); //Exchange above line to this line ?
this->panel1->SuspendLayout();


	// 
	// panel1 (holds 200 buttoncontrols that flickers for 2 seconds)
	// 
	this->panel1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"panel1.BackgroundImage")));
	this->panel1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
	this->panel1->Controls->Add(this->linkLabel3);
	this->panel1->Controls->Add(this->linkLabel2);
	this->panel1->Controls->Add(this->button266);

      //200 buttoncontrols here !!!!!!!

	this->panel1->Controls->Add(this->menuStrip1);
	this->panel1->Location = System::Drawing::Point(0, 0);
	this->panel1->Name = L"panel1";
	this->panel1->Size = System::Drawing::Size(854, 537);
	this->panel1->TabIndex = 0;

	// 
	// Form2 (Form2 holds the panel)
	// 
	this->panel1->ResumeLayout(false);
	this->panel1->PerformLayout();
	this->DoubleBuffered = true;

The "problem" is more than likely too many button controls :icon_eek: Maybe you need to redesign the project so that it doesn't contain so many controls.

Is it true that it really are to many buttoncontrols and that there aren´t any solution to this ?

Every buttoncontrol that I have changes to a Color when the button is pressed and all 200 buttons are neccesary.
As default all buttons have a transparent background. But these transparant buttoncontrols are the ones that "Flickers" anyway.


The "problem" is more than likely too many button controls :icon_eek: Maybe you need to redesign the project so that it doesn't contain so many controls.

>>Is it true that it really are to many buttoncontrols and that there aren´t any solution to this ?
No -- I lied :)

If all those buttons do is change the color of a rectangle somewhere on the screen you can do that without any buttons at all. Just capture the mouse click event, and change the rectangle under the mouse. You could also simulate a button click by calculating a hit test to see what button would have been pressed had there been a real button control there and acting accordingly.

For example you can set up an array of 200 RECT structures that have x,y coordinates along with hight and width. Given this info for each rectangle when a mouse is clicked test each RECT to see if the mouse's x/y coordinate lies within the boundries of the RECT. That is essentially what the os has to do with button controls.

Okay! I beleive that will be a very hard work to do.

What happens in this case is that when leftclick the button, it changes to a green color and also for each left click increase an integer by +1 each time for the Textproperty.

I think I may ask this question:

If I have the FormWindow open with the 200 buttoncontrols inside the panel and now open up Notepad wich is also is a FormWindow and place that Form over the panel with the 200 buttons and now minimize the Notepad window.
Just in that very moment all 200 buttoncontrols "flickers".

I beleive what happens is that the controls are redrawing themselves ?

So my question is if it is possible in code to tell that the buttoncontrols only will redraw themselves if the Form window is Focused because when the Notepadwindow is over the buttons the Form is UnFocused ?

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.