The problem with using the CreateGraphics call for any purpose other than
obtaining data about the Graphics object of a particular window is that it
breaks the fundamental principle of event driven programming.
Windows is an event driven system in which things happen in order and for a
purpose. When you write code that refuses to follow the order of events as
dictated by the system you will have your own misguided efforts walked upon
by the *correct functioning* of the system.
Painting using CreateGraphics will almost inevitably be overprinted by the
OnPaint method and causes huge numbers of questions from inexperienced
programmers who think that there is some sort of system error when it's
their own code that's at fault. This is why it's still the GDI+ FAQ most
asked question despite three years of the answer being available for all to
see with a simple google search.
It's also why I generally answer such questions with a brusque "RTFM" style
answer so, after you've "Read That Fine Material" ;-) you'll understand
fully.
Microsoft's operating systems, including Longhorn, will continue to be event
driven and will exhibit the same behaviours if event order is ignored
whether it's GDI, GDI+ or Avalon doing the drawing.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.