如何在winforms选项卡控件选项卡页上显示多个图标?

如何在winforms选项卡控件选项卡页上显示多个图标?,winforms,tabcontrol,imagelist,Winforms,Tabcontrol,Imagelist,我不知道这是否可能,但也许有人找到了一种方法来做到这一点。。。 我有一个选项卡控件,允许用户通过单击按钮添加选项卡。 我想在选项卡上显示一些图标,因此我添加了一个ImageList,但我一次只能显示一个图标,并且我需要同时显示至少3个图标。 我曾考虑将3个图标放在一起,但图标是在使用过程中的一些动作之后显示的。例如:首先,我显示图标_1,如果用户单击我添加图标_2等的某些位置。。。 有人能想出一个办法吗? 非常感谢您……不,这是不可能的。使用标准WinForms组件,您只能同时显示一个图像 这里

我不知道这是否可能,但也许有人找到了一种方法来做到这一点。。。 我有一个选项卡控件,允许用户通过单击按钮添加选项卡。 我想在选项卡上显示一些图标,因此我添加了一个ImageList,但我一次只能显示一个图标,并且我需要同时显示至少3个图标。 我曾考虑将3个图标放在一起,但图标是在使用过程中的一些动作之后显示的。例如:首先,我显示图标_1,如果用户单击我添加图标_2等的某些位置。。。 有人能想出一个办法吗?
非常感谢您……

不,这是不可能的。使用标准WinForms组件,您只能同时显示一个图像

这里的解决方案是使用覆盖图标。您有一个基本图标,并添加装饰器。这就是乌龟SVN的方式,例如

以下代码在C#中构建一个覆盖图像:

注意:叠加图像的大小必须与基础图像相同。它必须具有透明的颜色,并且叠加图像中的装饰器必须放置在正确的位置,例如右下角或右上角。

我发现以下代码:

private Bitmap CombineImages(params Image[] images)
    {
        int width = 0;
        for (int i = 0; i < images.Length; i++)
            width += images[i].Width + 3;

        int height = 0;
        for (int i = 0; i < images.Length; i++)
        {
            if (images[i].Height > height)
                height = images[i].Height;
        }
        int nIndex = 0;
        Bitmap fullImage = new Bitmap(width, height);
        Graphics g = Graphics.FromImage(fullImage);
        g.Clear(SystemColors.AppWorkspace);
        foreach (Image img in images)
        {
            if (nIndex == 0)
            {
                g.DrawImage(img, new Point(0, 0));
                nIndex++;
                width = img.Width;
            }
            else
            {
                g.DrawImage(img, new Point(width, 0));
                width += img.Width;
            }
        }
        return fullImage;
        //img3.Save(finalImage, System.Drawing.Imaging.ImageFormat.Jpeg);
        //img3.Dispose();
        //imageLocation.Image = Image.FromFile(finalImage);
    }
专用位图组合图像(参数图像[]图像)
{
整数宽度=0;
对于(int i=0;i高度)
高度=图像[i]。高度;
}
int-nIndex=0;
位图fullImage=新位图(宽度、高度);
Graphics g=Graphics.FromImage(fullImage);
g、 清除(SystemColors.AppWorkspace);
foreach(图像中的图像img)
{
如果(nIndex==0)
{
g、 DrawImage(img,新点(0,0));
nIndex++;
宽度=最小宽度;
}
其他的
{
g、 DrawImage(img,新点(宽度,0));
宽度+=最小宽度;
}
}
返回完整图像;
//img3.Save(finalImage、System.Drawing.Imaging.ImageFormat.Jpeg);
//img3.Dispose();
//imageLocation.Image=Image.FromFile(finalImage);
}

通过此链接

我想尝试一下,但您锁定的对象是什么<代码>锁定(mOverlayLock)?是的,这就是覆盖的内容。这是当你需要用装饰来表示一个基础图像时使用的。对不起,这不是我需要的。我需要能够同时显示多个图标。您可以使用TabControl.DrawMode+DrawItem成员绘制所需的任何内容。您可能需要使用
TabControl
event of
DrawMode
属性设置为
OwnerDrawFixed
private Bitmap CombineImages(params Image[] images)
    {
        int width = 0;
        for (int i = 0; i < images.Length; i++)
            width += images[i].Width + 3;

        int height = 0;
        for (int i = 0; i < images.Length; i++)
        {
            if (images[i].Height > height)
                height = images[i].Height;
        }
        int nIndex = 0;
        Bitmap fullImage = new Bitmap(width, height);
        Graphics g = Graphics.FromImage(fullImage);
        g.Clear(SystemColors.AppWorkspace);
        foreach (Image img in images)
        {
            if (nIndex == 0)
            {
                g.DrawImage(img, new Point(0, 0));
                nIndex++;
                width = img.Width;
            }
            else
            {
                g.DrawImage(img, new Point(width, 0));
                width += img.Width;
            }
        }
        return fullImage;
        //img3.Save(finalImage, System.Drawing.Imaging.ImageFormat.Jpeg);
        //img3.Dispose();
        //imageLocation.Image = Image.FromFile(finalImage);
    }