severe flicker in a panel on a form

fguihen

Junior Contributor
Joined
Nov 10, 2003
Messages
248
Location
Eire
i have a panel on a form onto which im drawing a little moving simulation. i had this working perfectly , flicker free on the form, but when i tried to put it on the panel it is terrible. i have overridden the panel_OnPaint() method to this:

Code:
private void Pannel_Paint(object sender, System.Windows.Forms.PaintEventArgs g)
		{//top walls
			g.Graphics.FillRectangle(Brushes.Cyan,1,1,this.Width,this.Height);
			
			foreach (Wall w in this.walls)
			{
				w.DrawWall(g.Graphics);
			}
		
			crowd.DrawToScreen(g.Graphics);
			panel1.Invalidate();
		}

i have the doubble buffering set up here

Code:
SetStyle(ControlStyles.UserPaint, true);
			SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			SetStyle(ControlStyles.DoubleBuffer, true);

i have overridden the onPaintBackground() to do nothing.
i have tried overriding and leaving the form1_onPaint() but still the same problem happens. any ideas on what i can do now?
 
Last edited:
This is just a guess, but what happens if you take out that invalidate() call:
panel1.Invalidate();

Assuming that the panel you're drawing to is actually called panel1 and not Pannel, it shouldn't even be needed.
 
The .Invalidate() function call tells the control that it needs to be redrawn, doesn't it?

I get confused sometimes by control invalidation and painting and drawing, so don't yell at me if im wrong, but if you were modifying a bitmap that were persited to the panel, this would be necessary. It appears that you are using the graphics object given in the event arguments which will cause you to draw directly on the screen. Should a call to invalidate cause the control to be redrawn and erase your picture?
 
marble_eater said:
The .Invalidate() function call tells the control that it needs to be redrawn, doesn't it?

I get confused sometimes by control invalidation and painting and drawing, so don't yell at me if im wrong, but if you were modifying a bitmap that were persited to the panel, this would be necessary. It appears that you are using the graphics object given in the event arguments which will cause you to draw directly on the screen. Should a call to invalidate cause the control to be redrawn and erase your picture?
If the paint event is running, it's already being redrawn, so there is no need to tell it, because it already knows by then. That's why it's painting. The Paint event is what redraws the control.
 
if i dont put in invalidate then the simulation im drawing to the pannel wont ever get updated. you see , each time the paint method for the pannel is called, the charachters move on a position and then they are drawn to the panel in their new position. thanks anyway
 
Back
Top