By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,479 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

screen flickering

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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

Nov 16 '05 #2

P: n/a
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


Nov 16 '05 #3

P: n/a
"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
>
>



Nov 16 '05 #4

P: n/a
benben wrote:
What is the general strategy to reduce screen flickering with C# Forms?


Try reducing hardware acceleration of the display.
Nov 16 '05 #5

P: n/a
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.

Nov 16 '05 #6

P: n/a
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
>
>



Nov 16 '05 #7

P: n/a
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
>> >
>> >
>>
>>
>
>



Nov 16 '05 #8

P: n/a
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
>
>



Nov 16 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.