Icons in VB

  • Thread starter Thread starter Stephen Turner
  • Start date Start date
S

Stephen Turner

Hi,

I have implemented a COM object in .NET, and I simply want
to load an icon resource and pass back an IPictureDisp to
clients. What is the esiest way to do this? I had used
LoadResPicture in VB, but I havent been able to
create/load an icon resource in VB .NET. I'm sure that
this should be simple....by so far I am failing miserably!

Any suggestions? The documentation babbles on and on
about .resx, .resource and silly little conversion
programs but doesn't really give any clear examples...
 
Hi Stephen,

There's a forum on VS .NET add-ins:

http://groups.yahoo.com/groups/vsnetaddin

and there has been a topic recently where a multi-purpose class doing this
..NET <-> IPictureDisp translation was discussed. You could also conduct a
search on "IPictureDisp" in this forum - as I have also seen other postings
on the same topic.
 
COM is, uh, outside my area of expertise (come to think of it, so far
everything in VB is), and I dunno if it's close to what you need, but
here's how I bundled an icon into an executable and accessed it:

----------

1. Added the icon file to the solution.
2. Highlighted the icon in the Solution Explorer, and changed the Build
Action property to "Embedded Resource".
3. In a module, inserted a function to retrieve the icon:

Imports System.Reflection.Assembly

Public Function EmbeddedIcon(ByVal Name as String) as Icon

Return New
Icon(GetExecutingAssembly.GetManifestResourceStream(Name))

End Function

4. Elsewhere in the program, accessed the icon like so:

TrayIcon.Icon = EmbeddedIcon("<namespace>.<icon-name>.ico")

----------

Obviously, or maybe not, <namespace> stands for the namespace, and
"<icon-name>.ico" stands for the file name of the icon I added in step
1. Apparently it's all case-sensitive, so be careful with that.

The procedure worked like a charm for me, but I'm a little
uncomfortable with it, because I got lucky in specifying the
namespace -- I just used the project name, and it was fine. I'm not
certain yet how multiple namespaces might be created and used in a
project.

Plenty to learn, plenty to learn...
 
Back
Top