Bobo the Thief
05-30-2004, 05:27 AM
I'm doing C# but since this is about GDI+ I'll go ahead and ask.
Can I do something about flickering?? I use, in C#, a TextBox control with its associated Graphics object.
I'm just using DrawLines & Drawline and Clear methods.
Maybe use APIs?? I tried that, but when trying to retrieve the HDC of the Graphics object I'm getting some runtime error saying "object already in use";
Please help.
thanks. helix
Iceplug
05-30-2004, 08:30 AM
How many lines are you drawing and what are they doing?
You may want to ask at http://www.dotnetforums.net/ for C#. :)
Bobo the Thief
05-31-2004, 02:58 PM
How many lines are you drawing and what are they doing?
As for the lines, they aren't a big deal. The procedure that updates the picturebox first clears it then draws a grid - that is, about ... 200 lines, at most.
Think about it: the coordinates of the line endpoints need almost no computing, and, anyway, I have a pretty good computer.
However, the picturebox is pretty big and the lines are long, plus, they make translations at each frame (that is, very frequently - at each mouseMove).
The flickering is very disturbing, sometimes you can hardly distinguish what's moving ... it's similar to the effect of a 20hz monitor refresh or something, you see alternate rows of darkness/color rolling over the screen.
I'm doing C# but since this is about GDI+ I'll go ahead and ask.
Can I do something about flickering?? I use, in C#, a TextBox control with its associated Graphics object.
I'm just using DrawLines & Drawline and Clear methods.
Maybe use APIs?? I tried that, but when trying to retrieve the HDC of the Graphics object I'm getting some runtime error saying "object already in use";
Please help.
thanks. helix
Taken From MSDN:
' To avoid both unnecessary work and flicker, you want the minimum amount
' of control redrawing, but in this case every resize will require a redraw.
' Sometimes you cannot avoid redrawing due to the nature of your UI design,
' as is the case with this control. I am drawing two arrows (one at the top
' and one at the bottom of the control) to indicate when there are more
' items available off screen. To force a redraw upon every resize, I could add
' a call to Me.Invalidate within this Resize routine, but Windows Forms
' provides another method through the use of control styles. By adding calls
' to the SetStyle method in the constructor (New method) of our control, we
' can control how it is drawn and refreshed by the Windows Forms engine. In
' this case, setting the ResizeRedraw style will force a refresh whenever the
' control is resized, but I will also set the DoubleBuffer style, as it is an
' excellent way to remove flicker from a custom drawn control:
Public Sub New()
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub
' Note Double buffering is a graphic technique where a complete image of
' the user interface is drawn into a buffer (such as an Image object in
' memory) and then drawn out to the window as a single image. This greatly
' reduces flicker compared to executing all the individual graphic commands
' directly onto the window one at a time. According to the .NET Framework
' documentation for the ControlStyles options, I need to set UserPaint and
' AllPaintingInWmPaint to gain the full benefits of double buffering.