fguihen Posted February 28, 2005 Posted February 28, 2005 (edited) 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: 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 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? Edited February 28, 2005 by fguihen Quote
Tygur Posted March 1, 2005 Posted March 1, 2005 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. Quote
Leaders snarfblam Posted March 1, 2005 Leaders Posted March 1, 2005 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? Quote [sIGPIC]e[/sIGPIC]
IngisKahn Posted March 1, 2005 Posted March 1, 2005 Bingo. Don't call invalidate in the Paint event. Quote "Who is John Galt?"
Tygur Posted March 1, 2005 Posted March 1, 2005 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. Quote
fguihen Posted March 1, 2005 Author Posted March 1, 2005 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.