I created a form and overrided OnPaint, OnClick and OnResize methods. My
OnPaint calls base.OnPaint then repaints the whole screen.
The screen flickers a lot! It didn't happen when the app was written in C++.
What is the general strategy to reduce screen flickering with C# Forms?
Perhaps saving the screen as a bitmap and just bitblip when painted, and
only change the bitmap when necessary? is it possible?
ben 8 16602
Try this in your Form's constructor:
this.SetStyle(System.Windows.Forms.ControlStyles.D oubleBuffer, true);
-vJ
"benben" <be******@yahoo.com.au> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl... I created a form and overrided OnPaint, OnClick and OnResize methods. My OnPaint calls base.OnPaint then repaints the whole screen.
The screen flickers a lot! It didn't happen when the app was written in C++.
What is the general strategy to reduce screen flickering with C# Forms? Perhaps saving the screen as a bitmap and just bitblip when painted, and only change the bitmap when necessary? is it possible?
ben
What does it buffer?
Plus, I do not use standard controls in this project, instead I paint
directly to the form using GDI+.
ben Try this in your Form's constructor:
this.SetStyle(System.Windows.Forms.ControlStyles.D oubleBuffer, true);
-vJ
"benben" <be******@yahoo.com.au> wrote in message news:uL**************@TK2MSFTNGP12.phx.gbl...I created a form and overrided OnPaint, OnClick and OnResize methods. My OnPaint calls base.OnPaint then repaints the whole screen.
The screen flickers a lot! It didn't happen when the app was written in C++.
What is the general strategy to reduce screen flickering with C# Forms? Perhaps saving the screen as a bitmap and just bitblip when painted, and only change the bitmap when necessary? is it possible?
ben
"benben" <be******@yahoo.com.au> wrote in message
news:en**************@TK2MSFTNGP09.phx.gbl... What does it buffer?
Instead of drawing directly onto the screen, it buffers the image to an
in-memory bitmap, and then blits the bitmap onto the screen. This does
reduce flicker, although your problem might also be caused by the parent
classes OnPaintBackground implementation. You can override this, and not do
anything in it, or you could set the control Style AllPaintingInWmPaint. I
personally prefer this method, in fact, I usually set the following:
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint,
ControlStyles.UserPaint, true);
HTH
--
Sean Hederman http://codingsanity.blogspot.com
Plus, I do not use standard controls in this project, instead I paint directly to the form using GDI+.
ben
Try this in your Form's constructor:
this.SetStyle(System.Windows.Forms.ControlStyles.D oubleBuffer, true);
-vJ
"benben" <be******@yahoo.com.au> wrote in message news:uL**************@TK2MSFTNGP12.phx.gbl... >I created a form and overrided OnPaint, OnClick and OnResize methods. My > OnPaint calls base.OnPaint then repaints the whole screen. > > The screen flickers a lot! It didn't happen when the app was written in > C++. > > What is the general strategy to reduce screen flickering with C# Forms? > Perhaps saving the screen as a bitmap and just bitblip when painted, > and > only change the bitmap when necessary? is it possible? > > ben > >
benben wrote: What is the general strategy to reduce screen flickering with C# Forms?
Try reducing hardware acceleration of the display.
I don't think I can do that to my user even if it is applicable. but thanks
anyway for your suggestion!
ben benben wrote: What is the general strategy to reduce screen flickering with C# Forms?
Try reducing hardware acceleration of the display.
Thanks Sean!! The problem does improved with your suggestion!!
Just for a matter of interest: if the form buffers the screen, how can I get
access to this bitmap?
Another question: I have been using the Graphics object as the painting
surface. Instead of a Graphics object associated with the actual screen, can
i create other Graphics objects that are associated to 1. a printing surface
2. a bitmap image?
ben "benben" <be******@yahoo.com.au> wrote in message news:en**************@TK2MSFTNGP09.phx.gbl... What does it buffer? Instead of drawing directly onto the screen, it buffers the image to an in-memory bitmap, and then blits the bitmap onto the screen. This does reduce flicker, although your problem might also be caused by the parent classes OnPaintBackground implementation. You can override this, and not
do anything in it, or you could set the control Style AllPaintingInWmPaint. I personally prefer this method, in fact, I usually set the following:
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, ControlStyles.UserPaint, true);
HTH
-- Sean Hederman
http://codingsanity.blogspot.com
Plus, I do not use standard controls in this project, instead I paint directly to the form using GDI+.
ben
Try this in your Form's constructor:
this.SetStyle(System.Windows.Forms.ControlStyles.D oubleBuffer, true);
-vJ
"benben" <be******@yahoo.com.au> wrote in message news:uL**************@TK2MSFTNGP12.phx.gbl... >I created a form and overrided OnPaint, OnClick and OnResize methods.
My > OnPaint calls base.OnPaint then repaints the whole screen. > > The screen flickers a lot! It didn't happen when the app was written
in > C++. > > What is the general strategy to reduce screen flickering with C#
Forms? > Perhaps saving the screen as a bitmap and just bitblip when painted, > and > only change the bitmap when necessary? is it possible? > > ben > >
Yes, you can do that. You can use the same code for both. If you want to get
the buffer, it is best to do the double buffering yourself, writing to a
Graphics created from a bitmap, and transferring the bitmap to the
paint-provided Graphics when done.
Regards,
Frank Hileman
check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor
"benben" <be******@yahoo.com.au> wrote in message
news:O5**************@TK2MSFTNGP11.phx.gbl... Thanks Sean!! The problem does improved with your suggestion!!
Just for a matter of interest: if the form buffers the screen, how can I get access to this bitmap?
Another question: I have been using the Graphics object as the painting surface. Instead of a Graphics object associated with the actual screen, can i create other Graphics objects that are associated to 1. a printing surface 2. a bitmap image?
ben
"benben" <be******@yahoo.com.au> wrote in message news:en**************@TK2MSFTNGP09.phx.gbl... > What does it buffer?
Instead of drawing directly onto the screen, it buffers the image to an in-memory bitmap, and then blits the bitmap onto the screen. This does reduce flicker, although your problem might also be caused by the parent classes OnPaintBackground implementation. You can override this, and not do anything in it, or you could set the control Style AllPaintingInWmPaint. I personally prefer this method, in fact, I usually set the following:
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, ControlStyles.UserPaint, true);
HTH
-- Sean Hederman
http://codingsanity.blogspot.com
> Plus, I do not use standard controls in this project, instead I paint > directly to the form using GDI+. > > ben > >> Try this in your Form's constructor: >> >> this.SetStyle(System.Windows.Forms.ControlStyles.D oubleBuffer, true); >> >> -vJ >> >> "benben" <be******@yahoo.com.au> wrote in message >> news:uL**************@TK2MSFTNGP12.phx.gbl... >> >I created a form and overrided OnPaint, OnClick and OnResize methods. My >> > OnPaint calls base.OnPaint then repaints the whole screen. >> > >> > The screen flickers a lot! It didn't happen when the app was written in >> > C++. >> > >> > What is the general strategy to reduce screen flickering with C# Forms? >> > Perhaps saving the screen as a bitmap and just bitblip when painted, >> > and >> > only change the bitmap when necessary? is it possible? >> > >> > ben >> > >> > >> >> > >
I found a trick!
In my original tests I used newly created Graphics objects, e.g.
Graphics paintSurface = Graphics.FromHwnd(this.Handle);
And there was a lot of screen flickering.
Once I found that there is already a Graphics object in the PaintEventArgs
parameter passed into my OnPaint, I started to use it and the flickering
disappeared!
Why does creating a new Graphics object out of the window handle create such
an overhead?
ben "benben" <be******@yahoo.com.au> wrote in message news:en**************@TK2MSFTNGP09.phx.gbl... What does it buffer? Instead of drawing directly onto the screen, it buffers the image to an in-memory bitmap, and then blits the bitmap onto the screen. This does reduce flicker, although your problem might also be caused by the parent classes OnPaintBackground implementation. You can override this, and not
do anything in it, or you could set the control Style AllPaintingInWmPaint. I personally prefer this method, in fact, I usually set the following:
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, ControlStyles.UserPaint, true);
HTH
-- Sean Hederman
http://codingsanity.blogspot.com
Plus, I do not use standard controls in this project, instead I paint directly to the form using GDI+.
ben
Try this in your Form's constructor:
this.SetStyle(System.Windows.Forms.ControlStyles.D oubleBuffer, true);
-vJ
"benben" <be******@yahoo.com.au> wrote in message news:uL**************@TK2MSFTNGP12.phx.gbl... >I created a form and overrided OnPaint, OnClick and OnResize methods.
My > OnPaint calls base.OnPaint then repaints the whole screen. > > The screen flickers a lot! It didn't happen when the app was written
in > C++. > > What is the general strategy to reduce screen flickering with C#
Forms? > Perhaps saving the screen as a bitmap and just bitblip when painted, > and > only change the bitmap when necessary? is it possible? > > ben > >
This discussion thread is closed Replies have been disabled for this discussion. Similar topics
2 posts
views
Thread by karthigan |
last post: by
|
1 post
views
Thread by RickN |
last post: by
|
2 posts
views
Thread by John Lee |
last post: by
|
2 posts
views
Thread by John Lee |
last post: by
|
reply
views
Thread by benben |
last post: by
|
5 posts
views
Thread by n00b |
last post: by
|
6 posts
views
Thread by Mark Thompson |
last post: by
|
3 posts
views
Thread by piers.allard |
last post: by
|
1 post
views
Thread by =?Utf-8?B?Umljaw==?= |
last post: by
| | | | | | | | | | |