In the first instance you're trying to draw an image onto itself. This won't
work. In the second you're drawing it onto the form's surface in the correct
manner.
You probably need to be reading the GDI+ FAQ to retain your sanitiy.
--
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.
"Barry" <so*****@somwhere.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi
why does the following code not display the image
public Form1()
{
InitializeComponent();
Bitmap imgBg = new Bitmap("Monitor.bmp");
Graphics gr = Graphics.FromImage(imgBg);
gr.DrawImage(imgBg, new Rectangle(10,10, imgBg.Width, imgBg.Height));
}
if i shift the above code in the paint event like this it displays the
bitmap
private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Bitmap imgBg = new Bitmap("Monitor.bmp");
e.Graphics.DrawImage(imgBg, new Rectangle(10,10, imgBg.Width,
imgBg.Height));
}
Barry