Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo
How to reference an embedded icon file (Saturday, August 28, 2004)
 

Found the following interesting discussion in the Newsgroups:

Embedded icon file - how to reference?
by:Wayne Hoover

I have an embedded icon resource in my project - I need to reference this icon for a grid cell. I've tried using the following but it does not work. Any help appreciated:


Dim im As System.Drawing.Image
im = CType(getobject("CHECKMRK.ICO"), _
System.Drawing.Image) <-- Fails here.
g_mainform.fg.SetCellImage(g_mainform.FG.Row _
, 5, im)




 Reply:
by:Ken Tucker [MVP]

 Hi,


Dim ico As Icon

Dim p As System.Reflection.Assembly =
System.Reflection.Assembly.GetExecutingAssembly()

ico = New System.Drawing.Icon _
(p.GetManifestResourceStream(Me.GetType, "Icon1.ico"))


Ken


 Reply:
by:Wayne Hoover

 Thanks, Ken.



 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
Add the icon file to your project and set its 'Build Action' property to
'Embedded Resource'. You can use the code below to load the icon at
runtime:


\\foo.Icon = _
New Icon( _
[Assembly].GetExecutingAssembly().GetManifestResourceStream( _
"WindowsApplication1.Ball.ico" _
) _
)
///


'WindowsApplication1' is the root namespace of the application, "Ball.ico"
is the icon's filename.

--
Herfried K. Wagner [MVP]
URL:http://dotnet.mvps.org/


 Reply:
by:Wayne Hoover

 Hi Herfried --

I tried the prior response and now get this:


g_mainform.fg.SetCellImage(g_mainform.FG.Row, 5, chkMarkico)


Value of type 'System.Drawing.Icon' cannot be converted to 'System.Drawing.Image'.

Any help appreciated!


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
Icons are not images for .NET! You may want to use a bitmap instead of
an icon.

--
Herfried K. Wagner [MVP]
URL:http://dotnet.mvps.org/



Posted by Xander Zelders



 
Previous Posts
    - Returning Integer from String
    - Expiring the Page To discourage Browser BACK butto...
    - How to use a treeview control
    - Clipboard in console application
    - How to manage a listbox from javascript
    - Deploying MSDE with VB.net
    - Remove a line from a text file
    - Remove the last line in a text file
    - How to launch a .doc or .exe file with VB.NET
    - How to send a file with VB.NET

Archives
    - 08/01/2004 - 08/08/2004
    - 08/08/2004 - 08/15/2004
    - 08/15/2004 - 08/22/2004
    - 08/22/2004 - 08/29/2004
    - 08/29/2004 - 09/05/2004
    - 09/05/2004 - 09/12/2004
    - 09/12/2004 - 09/19/2004
    - 09/19/2004 - 09/26/2004
    - 09/26/2004 - 10/03/2004
    - 10/03/2004 - 10/10/2004
    - 01/02/2005 - 01/09/2005
    - 01/09/2005 - 01/16/2005
    - 01/30/2005 - 02/06/2005
    - 01/01/2006 - 01/08/2006


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland