【问题标题】:How can I build C# ImageList Images from smaller component images?如何从较小的组件图像构建 C# ImageList 图像?
【发布时间】:2010-09-10 22:40:50
【问题描述】:

我想为 C# WinForms TreeList 控件制作状态图标。状态是其他状态的组合(例如,用户节点可能是非活动或被禁止或非活动和被禁止),状态图标由不重叠的较小字形组成。

如果可以的话,我真的很想避免手动生成状态图标的所有可能排列。

是否可以创建一个图像列表(或只是一堆位图资源或其他东西),我可以使用它以编程方式生成 ImageList?

我在 System.Drawing 类中闲逛,但没有任何反应。另外,我坚持使用 .Net 2.0。

【问题讨论】:

    标签: c# winforms image .net-2.0 system.drawing


    【解决方案1】:
    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);
    

    【讨论】:

      【解决方案2】:

      只需使用 ImageList 中的 Images.Add 来添加单个图像。所以,类似:

      
      Image img = Image.FromStream( /*get stream from resources*/ );
      ImageList1.Images.Add( img );
      

      【讨论】:

        猜你喜欢
        • 2021-02-04
        • 1970-01-01
        • 2012-07-20
        • 1970-01-01
        • 2023-03-30
        • 2015-08-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多