0

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

elCapitano
  • 121
  • 1
  • 9

3 Answers3

0

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"),
crypted
  • 10,118
  • 3
  • 39
  • 52
  • 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 Nov 25 '09 at 10:24
  • Ahh, My bad, it's even sealed. – crypted Nov 25 '09 at 10:29
0

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 );
RvdK
  • 19,580
  • 4
  • 64
  • 107
  • 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 Nov 25 '09 at 11:07
0

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
  • 121
  • 1
  • 9