Forms Icon: The argument 'picture' must be a picture that can be used as a Icon.

G

Greg Robinson

At designtime I can assingn a Form's Icon property to a .png file. In the
generated code I see:
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)

when I do this with the designer.

I would like to make this assignment at runtime. I added two .png files to
my Project and set them as Embedded Resources. I load the embedded resource
in the below method inside the Form:

Function GetEmbeddedIcon(ByVal strName As String) As System.Drawing.Icon

Dim stream As System.IO.Stream

Dim assm As System.Reflection.Assembly = Me.GetType().Assembly

stream =
assm.GetManifestResourceStream("CustomDataSystems.AMNET.Forms.Maintenance.UIElements"
& "." & strName)

Me.Icon = New System.Drawing.Icon(stream)

End Function

Where strName is the name of the png file.

I get:

"An unhandled exception of type 'System.ArgumentException' occurred in
system.drawing.dll

Additional information: The argument 'picture' must be a picture that can be
used as a Icon."

This implies to me you cannot assing a .png file to the Form's Icon
property, though I can do this at designtime and I see the icon.

Any idea what I am doing wrong here?
 
A

Armin Zingler

Greg Robinson said:
At designtime I can assingn a Form's Icon property to a .png file. In the
generated code I see:
Me.Icon = CType(resources.GetObject("$this.Icon"),
System.Drawing.Icon)

when I do this with the designer.

I would like to make this assignment at runtime. I added two .png
files to my Project and set them as Embedded Resources. I load the
embedded resource in the below method inside the Form:

Function GetEmbeddedIcon(ByVal strName As String) As
System.Drawing.Icon

Dim stream As System.IO.Stream

Dim assm As System.Reflection.Assembly =
Me.GetType().Assembly

stream =
assm.GetManifestResourceStream("CustomDataSystems.AMNET.Forms.Maintenance.UIElements"
& "." & strName)

Me.Icon = New System.Drawing.Icon(stream)

End Function

Where strName is the name of the png file.

I get:

"An unhandled exception of type 'System.ArgumentException' occurred
in system.drawing.dll

Additional information: The argument 'picture' must be a picture
that can be used as a Icon."

This implies to me you cannot assing a .png file to the Form's Icon
property, though I can do this at designtime and I see the icon.

Any idea what I am doing wrong here?


Are you sure you assigned a *.png file to the Form's icon property? I didn't
succeed in doing this.


Armin
 

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