PC Review


Reply
Thread Tools Rate Thread

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

 
 
Greg Robinson
Guest
Posts: n/a
 
      9th Jun 2005
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?




 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      10th Jun 2005
"Greg Robinson" <(E-Mail Removed)> schrieb
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
whether web service method's argument must be string? Raj Microsoft C# .NET 0 21st Jan 2010 10:27 AM
Throwing Argument exception when method argument is a Guid Andy B Microsoft VB .NET 2 11th Jan 2009 07:38 PM
Can UNC path be used as Data Source argument in OLE DB connection string? GY2 Microsoft ADO .NET 7 23rd Feb 2006 05:40 PM
Function (array argument, range argument, string argument) vba Witek Microsoft Excel Programming 3 24th Apr 2005 03:12 PM
How to overcome the limitation: Cannot pass 'argument' as ref or out, because ' argument ' is a marshal-by-reference class Mountain Bikn' Guy Microsoft C# .NET 2 15th Nov 2003 08:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:01 AM.