Solved

Winform Image Flickering

Posted on 2007-11-28
5
600 Views
Last Modified: 2013-12-16
Hi,
When I am loading the form the image which I draw on Paint is flickering. How do I avoid this?

 void Initial_Paint(object sender, System.EventArgs e)
 {
            Image newImage = Image.FromFile(ConfigurationManager.AppSettings["InitialFormImage"]);
            Graphics g = this.CreateGraphics();
            g.DrawImage(newImage, new Rectangle(new Point(CommonFunctions.GetWidth(60), CommonFunctions.GetHeight(100)), new Size(CommonFunctions.GetWidth(660), CommonFunctions.GetHeight(450))));
        }
0
Comment
Question by:AdibRahman77
  • 3
5 Comments
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 20367312
You need a separate graphics object that you draw to, and then replace the entire image (or at least, the entire portion that changed) at once.

Google "double buffering" for more information.  The third link down is .Net specific and indicates .Net may have a feature that does most of the work for you.
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 20367323
Hmm.. the sixth link down is even better.
0
 
LVL 18

Accepted Solution

by:
jcoehoorn earned 500 total points
ID: 20368268
0
 
LVL 3

Expert Comment

by:wizrr
ID: 20369706
And ofcourse you should not load that image every time OnPaint occurs. Hmm. Now i see that Initial_Paint is not paintevent, but you drawing from that method. You should draw only from OnPaint. Do not paint from another methods - this is OS rule, if you paint from another methods this is possible that OS will redraw (clean) all things you painted - that is why all can flicker.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question