Mick Dugan Posted December 28, 2005 Posted December 28, 2005 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 Quote
Cags Posted December 29, 2005 Posted December 29, 2005 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. Quote Anybody looking for a graduate programmer (Midlands, England)?
Mick Dugan Posted December 29, 2005 Author Posted December 29, 2005 Thanks Cags for the reply. I dont' know C# though. Could you post the code in VB for me? Thanx Quote
Cags Posted December 29, 2005 Posted December 29, 2005 My VB isn't great, but I think its this... Protected Overrides Sub OnPaintBackground(e As PaintEventArgs) 'MyBase.OnPaint(e) End Sub Quote Anybody looking for a graduate programmer (Midlands, England)?
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.