tags:

views:

174

answers:

3

Hi there,

does anybody know how i can change external icon-paths into embedded resource icons?

Example: i want to change the icon of my ToolBoxItem. I have only the possibility to set the path to the icon. Setting the picture directly does not work:

new ToolboxItemWrapper(typeof (MyItem9), "C:\\tmp\\item9.ico", "Item9"),

I want to change this path to the path of a embedded resource file:

new ToolboxItemWrapper(typeof (MyItem9), "MyAssembly.Resources.myIcon.ico", "Item9"),

Is there any possibility to do this? Or is there even a possibility to set the icon directly?

Thanks, el

A: 

Unless you change the signature of the hard-coded parameter(2nd one) that excepts file path in

new ToolboxItemWrapper(typeof (MyItem9), "C:\\tmp\\item9.ico", "Item9"),

you can not except the same result with this code.

ToolboxItemWrapper(typeof (MyItem9), "MyAssembly.Resources.myIcon.ico", "Item9"),

But you can do following, Create an overload of constructir of ToolboxItemWrapper like

public class ToolboxItemWrapper
{
    public ToolboxItemWrapper(Type t,Image img, string prop)
    {
        /*Do setup as in*/

    }
}

Later you could actually do ,

 new ToolboxItemWrapper(typeof (MyItem9), Properties.Resources.YourImage, "Item9"),
Int3
unfortunately the ToolboxItemWrapper is a micosoft constructed class. I knew that the second code would not work. This is wyh i asked this question. Do you know another solution for my problem?
elCapitano
Ahh, My bad, it's even sealed.
Int3
A: 

Whups, misread your post. You can't set the Icon directly, only from path

string res = "MyAssembly.Resources.myIcon.ico";
Stream s = this.GetType().Assembly.GetManifestResourceStream( res );
Icon icon = Icon.FromStream( s );
PoweRoy
oh... i think thats my fault. My explanation is not very good. In the end i want the path to the resource icon. Otherwise i could set the icon directly. Thanks anyway.
elCapitano
A: 

I could not figure it out how to solve this so i made a "dirty" workaround: I saved the icons in the temp folder and referenced them in this place. This works but it is not a very clean solution.

elCapitano