Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. samury

samury

Scheduled Pinned Locked Moved C#
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • L Lost User

      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

      G Offline
      G Offline
      gokselm
      wrote on last edited by
      #2

      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

      H A 2 Replies Last reply
      0
      • G gokselm

        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

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        There's also a shortcut using the right Icon constructor, Icon(Type, string). Like many other constructors (including many attribute constructors), the Type parameter is a type used for resource resolution. For instance, building on your example, lets say that you also had a class in the IconLibrary 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-----

        1 Reply Last reply
        0
        • G gokselm

          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

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Many thanks.... You code and explaination is most helpful..i will try it out. Regards Sam

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups