samury
-
Hi I wish to assign icons to the various buttons in my application by referencing them from an icon library in which they are present. Please let me know how i can do that. Thanks in advance Regs Sam
I just want to mention about one way doing this. You can create a resource dll and embed your resources to this dll choosing the Build Action as Embedded Resource. Then you can reach this icons as librray items. Imagine yo have the icon test.ico in IconLibrary namespace and you want to change your form's icon. System.IO.Stream st=assemblyExecuting.GetManifestResourceStream("IconLibrary.test.ico"); form.Icon=new System.Drawing.Icon(st); System.IO.Stream st=assemblyExecuting.GetManifestResourceStream("IconLibrary.test.ico"); Read the icon as stream form.Icon=new System.Drawing.Icon(st); Then set the form's icon. Yo can also use System.Drawing.Bitmap(st) to convert the image to the bitmap. Once you can get the image from the assembly you can use it in everywhere. I Hope it helps
-
I just want to mention about one way doing this. You can create a resource dll and embed your resources to this dll choosing the Build Action as Embedded Resource. Then you can reach this icons as librray items. Imagine yo have the icon test.ico in IconLibrary namespace and you want to change your form's icon. System.IO.Stream st=assemblyExecuting.GetManifestResourceStream("IconLibrary.test.ico"); form.Icon=new System.Drawing.Icon(st); System.IO.Stream st=assemblyExecuting.GetManifestResourceStream("IconLibrary.test.ico"); Read the icon as stream form.Icon=new System.Drawing.Icon(st); Then set the form's icon. Yo can also use System.Drawing.Bitmap(st) to convert the image to the bitmap. Once you can get the image from the assembly you can use it in everywhere. I Hope it helps
There's also a shortcut using the right
Icon
constructor,Icon(Type, string)
. Like many other constructors (including many attribute constructors), theType
parameter is a type used for resource resolution. For instance, building on your example, lets say that you also had a class in theIconLibrary
namespace. Specifying that Type plus "test.ico" in the constructor will cause the CLR to use that Type's namespace and append the resource name. This works a lot like relative paths in relation to directories on a filesystem or in a URL. So, the same thing would work with less code (and amounts to the same thing):Icon i = new Icon(typeof(IconLibrary.SomeClass), "test.ico");
form.Icon = i;Of course, this only works if you have a Type you can reference in that namespace, but I thought I'd mention it because a lot of libraries keep these in the same directories as their respective controls (though not all). In those cases, using this approach is a little easier.
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
I just want to mention about one way doing this. You can create a resource dll and embed your resources to this dll choosing the Build Action as Embedded Resource. Then you can reach this icons as librray items. Imagine yo have the icon test.ico in IconLibrary namespace and you want to change your form's icon. System.IO.Stream st=assemblyExecuting.GetManifestResourceStream("IconLibrary.test.ico"); form.Icon=new System.Drawing.Icon(st); System.IO.Stream st=assemblyExecuting.GetManifestResourceStream("IconLibrary.test.ico"); Read the icon as stream form.Icon=new System.Drawing.Icon(st); Then set the form's icon. Yo can also use System.Drawing.Bitmap(st) to convert the image to the bitmap. Once you can get the image from the assembly you can use it in everywhere. I Hope it helps