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?
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?