c# path to icon in ressources
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 pi开发者_运维问答cture 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
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 );
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"),
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.
精彩评论