Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using WMF file in picturebox

Status
Not open for further replies.

erithracus

Programmer
Oct 31, 2002
12
0
0
NL
Hello,

When I add a WMF file to a picturebox, the following code is generated:

this.pictureBox1.Image = ((System.Drawing.Imaging.Metafile)(resources.GetObject("pictureBox1.Image")));

When the application runs, an invalid cast exception rises. Apparently the result of "resources.GetObject("pictureBox1.Image"))" can not be casted to "System.Drawing.Imaging.Metafile".

Has anyone experience with WMF files?

TIA,


Jan
 
Just to let the people know who come across the same problem.

With the aid of Microsoft a workaround was found. It appeared to be a bug in VS.NET.
When a WMF file is serialized it is being saved as a bitmap. Instead of casting it to a metafile it should be casted to a bitmap.

Changing:

this.pictureBox1.Image = ((System.Drawing.Imaging.Metafile)(resources.GetObject("pictureBox1.Image")));

into:

this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));

solved the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top