Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Winform Image Flickering

Posted on 2007-11-28
5
Medium Priority
?
626 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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