There are two ways to achieve this:
Firstly, you can attach the Microsoft .Net ToolboxBitmapAttribute which allows you to refer to an Image or Icon that is contained in a resource.
One interesting quirk I noticed about this attribute is that when attaching it in VB.Net, the resource name must not be qualified with the root namespace, whereas with C#, it must be qualified. As an example, consider an embedded resource, 'myButtonImage.bmp', that you want to attach to the class, 'myButton', whose root namespace is 'myControls'. To attach the attribute in VB.Net, you would type:
<ToolboxBitmap(GetType(myButton), "myButton.bmp")>
... but to attach the attribute in C#, you would type:
[ToolboxBitmap(typeof(myButton), "myControls.myButtonImage.bmp")]
Secondly, you can attach a new AssociatedImageAttribute which allows you to refer to an Image or Icon that is contained in a resource file.
A resource file is a resource which, itself, contains a collection of resources. There is a default resource file created with every new project which you can find by going to the property pages and clicking the Resources tab. There you can add Icons, Images, Strings, etc.
As far as I know, it is not possible, using the ToolboxBitmapAttribute, to refer to a resource contained in a resource file, which is why I created the new attribute. Let me know in the comments if I'm wrong in this.
The syntax of the AssociatedImageAttribute is very similar to the ToolboxBitmapAttribute:
<AssociatedImage(GetType(TextPlugin), "TextPluginIcon")>
<AssociatedImage("rootNamespace.MyResources", GetType(myPlugin), "myPluginIcon")>
baseName
parameter of the ResourceManager class on MSDN.
No comments:
Post a Comment