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

Discussion in 'Microsoft Dot NET Framework Forms' started by Greg Robinson, Jun 9, 2005.

  1. 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?
     
    Greg Robinson, Jun 9, 2005
    #1
    1. Advertisements

  2. "Greg Robinson" <> 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
     
    Armin Zingler, Jun 10, 2005
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Rogers

    Is the one-argument extended control constructor significant?

    David Rogers, Jun 30, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    448
    David Rogers
    Jun 30, 2003
  2. Michael \(michka\) Kaplan [MS]

    Re: Restrict character set used in forms to West European characters

    Michael \(michka\) Kaplan [MS], Jul 3, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    521
    Michael \(michka\) Kaplan [MS]
    Jul 3, 2003
  3. Eashwar

    Datagrid: Specified argument was out of the range of valid values

    Eashwar, Jul 28, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    720
    Eashwar
    Jul 28, 2003
  4. powerranger

    pass a class as argument

    powerranger, Dec 14, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    190
    TheGrudge
    Dec 17, 2003
  5. Eric Newton

    intellectual argument about context menus

    Eric Newton, Dec 23, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    160
    Doug Forster
    Dec 23, 2003
Loading...

Share This Page