Programmatically Add Icon to Winform

P

Paul J. Lay

I can add an icon to a winform using the GUI but I cannot do it
programmatically.
Me.Icon = system.drawing.icon does not work for me. The same icon works
well in an imagelist when displayed in a listview in details mode. Thanks
for your help.

Best Regards,

Paul J. Lay
 
H

Herfried K. Wagner [MVP]

* "Paul J. Lay said:
I can add an icon to a winform using the GUI but I cannot do it
programmatically.
Me.Icon = system.drawing.icon does not work for me. The same icon works
well in an imagelist when displayed in a listview in details mode. Thanks
for your help.

The imagelist doesn't store icons, because icons are no images in .NET
terminology.

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.
 
P

Paul J. Lay

This works fine! Thanks very much for your prompt reply.

Best Regards,

Paul J. Lay
Herfried K. Wagner said:
* "Paul J. Lay said:
I can add an icon to a winform using the GUI but I cannot do it
programmatically.
Me.Icon = system.drawing.icon does not work for me. The same icon works
well in an imagelist when displayed in a listview in details mode. Thanks
for your help.

The imagelist doesn't store icons, because icons are no images in .NET
terminology.

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.
 

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

Similar Threads


Top