Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by fguihen
Posted

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.

  • Leaders
Posted

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?

[sIGPIC]e[/sIGPIC]
Posted
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.

Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...