|
|
Comments and Discussions
|
|
 |

|
Flicker free effect example is really good
|
|
|
|

|
Thanks very much! There's a way to take an existing control and set the style using reflection (where ctl is your control name):
ctl.GetType().GetMethod("SetStyle", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(ctl, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |ControlStyles.DoubleBuffer, true});
|
|
|
|

|
I tried this out for a DataGridView flicker problem -- it works great!
Thanks
|
|
|
|

|
Hi lads,
if you want to implement manual double buffering, you have to override the background painting method, too:
protected override void OnPaintBackground(PaintEventArgs pevent)
{
}
So long
Holger
|
|
|
|

|
I was getting ready to write a graphics test app but you wrote it for me.
Thank you!
|
|
|
|

|
I am creating a User Control.
I set DoubleBuffering = true from design time.
When i run my application and try to load an image then it shows me the
error saying "Parameter Not valid" on line Application.Run(new Form1());
When i set it to false everything is ok.
I also tried your method by writing this line on constructor but same error occurred.
this.SetStyle( ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
Help Needed
thanks,
adad
|
|
|
|

|
hi..
I have used the SetStype property that what u have used for BuiltInOptimisedBuffer, but still i have flickering problem..
If i open any other window in front of the painted area, it will again repaints the whole area, is there any way to not to effect the painted area, so that we can avoid repainting of that particular region..
|
|
|
|

|
Hi,
After putting this code in my control, it was still flickering, and I found the solution on another site : there's another parameter to pass to SetStyle (ControlStyles.DoubleBuffer).
Replace the SetStyle line by :
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
And after that it will work!
Thanks for this great article man
|
|
|
|

|
This is a great article on how to double buffer a single control, so that the rendering of the control does not flicker.
However I need to double buffer the entire control collection rendering. I use my own transparent image controls on my form which don't paint a background. These images change frequently so the entire control collection needs to be redrawn often. This causes severe flicker as each control is redrawn in the form.
How do I double buffer the rendering of all the form controls so that I don't actually see each control being rendered in turn? I basically need each control to be rendered to an in memory graphics buffer, and then when done, render the graphics buffer.
Thanks,
Johnny
|
|
|
|

|
Did you get an answer for this or find a solution yourself? Because I'm stuck with the same problem. I have created separate event handlers for the same control so any mouse movement will update all the controls, and their draw methods work fine with flicker actually, but when I try to introduce buffering to remove flicker, I lose them completely!
|
|
|
|

|
Question withdrawn... Turns out I got the ClientRectangles wrong.
|
|
|
|

|
i would recommand making a "master" function for drawing all the controls in one time and disabling the drawing of a control by itself, maybe even passing a common buffer for each one of the controls to draw them self onto the buffer and draw the whole buffer in one time by the master function when it's ready.
tell me if it helps
Gil
|
|
|
|

|
How do I have write code, if i want to use double buffer for picturebox in form?
|
|
|
|

|
this code is not for the existing controls but for writing your own custom controls.
from .Net 2 there's a double buffer property for the form (it's writtin in the article) i might help but i wouldn't count on it.
hope this helps..
|
|
|
|
|

|
Interesting article, however your handling of memory is problematic.
It is very unrecommended to have objects register to events from the Application class. It is not commonly known, but when you register to an event, that event keeps a reference to your object. This means that as long as the notifying object remains in memory, your object will NOT be garbage collected. In the case of Application, this means that every instance of your control class will remain in memory until the application is shut down!
The proper place to call dispose on any data members that you have on your control is in the control's Dispose method. This method is called when the control's window is destroyed (when its form is closed), or when it is garbage collected.
Some might notice that the Dispose method is auto-generated by the designer when you create a new Form or UserControl, but that doesn't mean you can't alter it. If you cut the method out of the *.designer.cs file, and put it in your code, the code generator will not attempt to recreate it.
|
|
|
|

|
I have tried your program,it worked well!
But there is still problem to use the bitmap as the backbuffer,When the picture size is tremendous,it waste so many memory,and also can't change the it's size! So I want to replace the Bitmap to the Metafile,but can't make it work!
|
|
|
|

|
hi man what`s up?
i`ll love to help but right now i`m travelling in south america for few more months, i`ll be back in march. i don`t deal with any programming right now and i must say that i never used Metafile so i need to check it out to get you an answer. but if you can try to check it out and change the code to see if it works with other formats, the thing is that the data is saved in memory maybe some other format will have better performence but i don`t know about the quality, i guess that it would be better to add some quality picker that would improve the performance instead of high quality graphics (for example a simple progress bar doesn`t need really high quality graphics)
well that`s it for now, hasta luego (until later)
|
|
|
|

|
I've tried the techniques above for my .net 2 app and to be honest the flickering is still present. This might have something to do with 2 forms being open both of which have the OnPaint method overridden. I wouldn't have thought that having two forms open would make such a difference but it does.
Levy
|
|
|
|

|
hi man..
i don't know how did you write the code but i hope that you've looked at the example that i gave here but from what i've tested it's supposed to work better with the double buffer techniques.
anyway right now i'm in south america so i don't have time to check it out, sorry.. Gil
|
|
|
|

|
The .NET 2.0 stuff saved my day.
Thanks
|
|
|
|

|
Nice article Gil.
I have a suggestion/question
With GDI drawing I use a forground and a background device context for applications where the forground changes regularily. The OnPaint blits the background and then the forground but does no operations on the device contexts. Instead all forground drawing is done on OnDraw and background drawing done in InvaliateControl.
As I am new to GDI+ is this something that you could add ? Is there an equivalent to BitBlt that would allow blending of forground and background bitmaps to save repeatably drawing the parts of the control that don't change very often?
cheers
Jason
|
|
|
|

|
hi JaseNet
am.. i don't know if you read the whole article but what double buffering is doing is to draw the the control graphics into an image in the memory and draw it only one time to the "real" surface of the control this improves the performance, if you'll check out the manual way it also disables the OnPaintBackground event so you draw the foreground and background together on a single paint event there isn't really a background just an event of drawing the control. about drawing parts of the control what the manual way gives you is a full control of the paint event so you don't really have to redraw the whole control each time you can write some code that will draw only the parts the you want.
about BitBlt i never had to use it on C# i used it in VB6 but that was long time ago, i'm sure you can use the API with [DllImport] just look around the net..
Gil
|
|
|
|

|
Hi Gil
Sorry for the confusion. I am fmiliar with double buffering and have read the article. I was looking for a way of extending it using C#. An example of what I was suggesting...
If you had a control that was dynamic and displayed a scrolling time history for several events such as the cpu usage display then there is a performance benefit in having the background of the control such as grids, axis, rotated text and watermarks predrawn on another drawing surface. The background surface would only change when the control was resized or for example the axis were changed.
The forground drawing surface would only have to contain the dynamic part of the data such as the trace information or rendered display or whatever. This would typically involve displaying a lot of data, say 4 times a second.
As GDI+ is not hardware accelerated it seemed like a good idea to adopt the GDI approach and use two surfaces. For most of the time no drawing would happen on the background surface, only the forground so the cpu is not wasting time constantly drawing all of the display, only the parts that changed.
I accept what you are saying about only updating the invalidated regions but in reality this would end up invalidating most, if not all of the display.
I have looked at alpha blending the two surfaces but the performance hit on GDI+ is too expensive.
thanks
Jason
|
|
|
|

|
hi again
well i think this is a good idea but it depends very much on the solution that is being built, and what i aimed for in this article is for the general use of the techniques of double buffering, your suggesting is very good and will surly be fitted in complex graphic project but in simple projects like a progress bar i don't know if it's worth the spending of time for it but on the next update for the article i'll mention it as a possibility.
i appreciate your comment Gil
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
Demonstrates several ways to overcome the annoying flickering problem.
| Type | Article |
| Licence | CPOL |
| First Posted | 29 Jan 2006 |
| Views | 222,719 |
| Bookmarked | 176 times |
|
|