Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi guys,

 

I have a problem with screen flicker. In my application, I�m drawing some objects in myPanel using myPanel.Paint. The coordinates of the objects (they�re mostly just primitives along with some regions) are stored in arrays. So when the graphics need to be refreshed, the arrays are consulted.

 

The problem is I also want to show items being dragged across the screen, but when I do that, the constant redrawing causes the screen to flicker. I�ve read that I should use the invalidate method, but can�t figure out where invalidate should be invoked.

 

Any ideas?

 

Cheers,

 

Michael Dugan

Posted

The most likely cause of the flicker is the OnPaintBackground event which fires before the OnPaint event. Using C# this can easily be solved by doing the following section of code. It is worth noting however that if you do override this method you must draw the entirity of the control (using either Graphics.Clear(), or another method such as DrawRectangle()) in the Paint method otherwise some sections will not get drawn

 

protected override void OnPaintBackground(PaintEventArgs pevent) 
{
//base.OnPaintBackground (pevent);
}

 

With regards to the Invalidate() method all this really does is tells a control to redraw to the screen. When used in conjunction with a bitmap buffer this can reduce the amount of calculations that are performed by the Paint event.

Anybody looking for a graduate programmer (Midlands, England)?
Posted

My VB isn't great, but I think its this...

Protected Overrides Sub OnPaintBackground(e As PaintEventArgs)
  'MyBase.OnPaint(e)
End Sub

Anybody looking for a graduate programmer (Midlands, England)?

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...