Can I draw a PNG file like this?

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.
 
K

Kevin Spencer

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
 
G

Guest

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.

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top