Search code examples
c#winformsimage.net-2.0system.drawing

How can I build C# ImageList Images from smaller component images?


I'd like to make status icons for a C# WinForms TreeList control. The statuses are combinations of other statuses (eg. a user node might be inactive or banned or inactive and banned), and the status icon is comprised of non-overlapping, smaller glyphs.

I'd really like to avoid having to hand-generate all the possibly permutations of status icons if I can avoid it.

Is it possible to create an image list (or just a bunch of bitmap resources or something) that I can use to generate the ImageList programmatically?

I'm poking around the System.Drawing classes and nothing's jumping out at me. Also, I'm stuck with .Net 2.0.


Solution

  • Bitmap image1 = ...
    Bitmap image2 = ...
    
    Bitmap combined = new Bitmap(image1.Width, image1.Height);
    using (Graphics g = Graphics.FromImage(combined)) {
      g.DrawImage(image1, new Point(0, 0));
      g.DrawImage(image2, new Point(0, 0);
    }
    
    imageList.Add(combined);