Solved

Winform Image Flickering

Posted on 2007-11-28
5
594 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now