Can I draw a PNG file like this?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,

I'm new here and I'm sorry to trouble.
But I've got the following problem when trying to draw a PNG file on a panel.
My code is like this:

Image mapImage = Image.FromFile (imageFileNames);
Graphics graphics = this.splitContainer1.Panel1.CreateGraphics();
graphics.Clear(this.splitContainer1.Panel1.BackColor);
graphics.DrawImage(mapImage, 10, 10, 50, 50);
this.splitContainer1.Panel1.Invalidate();

I can see that my imageFileNames is correct.
But the image fails to appear on the screen.
Would anyone please help me out?

Thanks in advance.
 
You have to draw it in the OnPaint method or the Paint event handler for the
Control.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
Thank you for reminding of this event.:)

I've tried the method.
And if I delete the last code, I can also make it.:)
Like this

Image mapImage = Image.FromFile (imageFileNames);
Graphics graphics = this.splitContainer1.Panel1.CreateGraphics();
graphics.Clear(this.splitContainer1.Panel1.BackColor);
graphics.DrawImage(mapImage, 10, 10, 50, 50);
//this.splitContainer1.Panel1.Invalidate();

Kevin Spencer said:
You have to draw it in the OnPaint method or the Paint event handler for the
Control.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

Kun Niu said:
Dear all,

I'm new here and I'm sorry to trouble.
But I've got the following problem when trying to draw a PNG file on a
panel.
My code is like this:

Image mapImage = Image.FromFile (imageFileNames);
Graphics graphics = this.splitContainer1.Panel1.CreateGraphics();
graphics.Clear(this.splitContainer1.Panel1.BackColor);
graphics.DrawImage(mapImage, 10, 10, 50, 50);
this.splitContainer1.Panel1.Invalidate();

I can see that my imageFileNames is correct.
But the image fails to appear on the screen.
Would anyone please help me out?

Thanks in advance.

 
Back
Top