473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

screen flickering

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
8 16879
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
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
"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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: karthigan | last post by:
I am writing a simple hardware test program in C that would run from Windows command line. Inside one of the loops, I have this code fragment that would display the Iteration count. { .......
1
by: RickN | last post by:
I have a form loaded with a full screen form image. I've overlayed a number of controls for filling in the form. When the form opens, I can watch as each control loads (flickering). It also does...
2
by: John Lee | last post by:
Hi, I have a windows application that uses the listview to display about 50 items in detailed view - 4 columns. The first column is static and other columns will be updated in 100-1000ms - it...
2
by: John Lee | last post by:
Thanks Jay for your response. I tried your code and it still flickering a lot. To demonstrate it, you can grab a listview, create 3 columns - name, value, timestamp, in form_load event to add 50...
0
by: benben | last post by:
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...
5
by: n00b | last post by:
I have some forms with maybe around 30 controls on each and anytime I load these forms different parts of it start flickering though not all of them at once and not the same ones everytime. the...
6
by: Mark Thompson | last post by:
I have a problem with my Visual Basic .NET 2003 application which I have so far been unable to resolve. I am trying to get an OpenGL control that I have created working properly as a control on...
3
by: piers.allard | last post by:
I am looking for assistance with an issue I am gettting with an Access2k application. When I have xp style switched on, switching from screen to screen causes the first screen to resize to it's...
1
by: =?Utf-8?B?Umljaw==?= | last post by:
I am trying to prevent screen flickering when clicked on a button; how do I use Hide Card in vs2005? Any other way?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.