Winform Image Flickering

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))));
Who is Participating?
Joel CoehoornConnect With a Mentor Director of Information TechnologyCommented:
Joel CoehoornDirector of Information TechnologyCommented:
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.
Joel CoehoornDirector of Information TechnologyCommented:
Hmm.. the sixth link down is even better.
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.
All Courses

From novice to tech pro — start learning today.