473,388 Members | 1,335 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,388 software developers and data experts.

How to avoid flicker when drawing

I'm a C# (but not programming in general) novice, but I couldn't find any
answer to this elsewhere.

I'm trying to make a text scroll on the form. I thought this was a good
example to get started with the encapsulated GDI+ functions.

So, I essentially have a Timer that raises a Tick event every 100
milliseconds, in which the program takes care of redrawing. The code is as
follows:

private void timer1_Tick(object sender, EventArgs e)
{

System.Drawing.Graphics drw;
drw = System.Drawing.Graphics.FromHwnd(this.Handle);
lastPoint++;
drw.FillRectangle(new SolidBrush(this.BackColor), new
Rectangle(0,0,this.Width,this.Height));
drw.DrawString(text, this.Font, System.Drawing.Brushes.White, new
Point(100, lastPoint));
}

lastPoint is an int declared directly in the form class and is used to make
the text appear a bit offset.

This code appears to be working fine - except of the flicker. The text
scrolls well, but it flickers annoyingly. Is there anything I can do to
prevent this? I already thought about just using labels instead of GDI+
functions to avoid the many redrawings.
Nov 17 '05 #1
2 11608
Try dropping this "magic" set of lines in your control constructor:

SetStyle(ControlStyles.DoubleBuffer, true);

SetStyle(ControlStyles.ResizeRedraw, true);

SetStyle(ControlStyles.AllPaintingInWmPaint, true);

SetStyle(ControlStyles.UserPaint, true);

cheers

dave
Nov 17 '05 #2
Also, try to avoid painting outside the OnPaint event handler. It's a bit of
a golden rule as far as i can tell. If you don't, everytime you draw your
new string, OnPaint will get called, possibly painting over what you just
did (which could explain the flicker), or all sorts of bad evil things.

cheers
dave
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Daniel | last post by:
how come when i do oGraphics.FillEllipse it draws blury? is there anyway to adjust this default compression to not be blury when drawing a simple ellipse?
2
by: Anand Ganesh | last post by:
Hi All, In my application I am allowing the user to draw a line. But when the user clicks the start point and starts moving the mouse there is a series of line generated. When the mouse is up...
1
by: Alessandro Fragnani | last post by:
Hi, I would like to know how to avoid flicker while adding controls to a panel. I couldn´t find any kind of "BeginUpdate/EndUpdate" on it. Thanks in advance Alessandro
6
by: johannblake | last post by:
I am wondering whether it is easy to setup a coordinate system for drawing (using GDI+) that uses meters (or any custom scaling for that matter). Currently, I need to convert from pixels to meters...
4
by: Thomas Richter | last post by:
Hi, I can't get of the black flicker when I resize my form. this = Mainform : System.Windows.Forms.Form If I set the size from 300 to 500 I see for ca 500ms some black areas. I try to solve it...
4
by: Marco Segurini | last post by:
Hi, I am trying to avoid flicker in this situation: 1) I create a simple VB6 Window application (a void form) and I define this code for the form (that has the autoredraw property set to...
3
by: Per Dunberg | last post by:
Hi all, I have to develop a "skinned" application and I have a problem with the graphics. When a form is loaded and displayed there's aways a flicker where all the controls are located on the...
0
by: Blue Apricot | last post by:
I think this is straighforward enough so I don't need sample code, but I will make an example if someone doesn't understand. BACKGROUND: We have built a "skinnable" interface, which uses...
6
by: abdunnabisk | last post by:
I am developing a program in c# where I have to show device connected each other in a dashboard.I am drawing in OnPaint event.when the user move the devices the background is flickering.because each...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.