Xel*_*Xel 11 c# tabcontrol winforms
我想在选项卡标题中放置一个图标,以便这样做

看起来像这样.

Ale*_*fie 16
您可以通过以下方式在VS Designer中执行此操作:
ImageList属性TabControl.ImageIndexor ImageKey属性设置为TabPage要显示的所需图像.如果您想在代码中完成所有操作,请按照以下步骤操作.
using System.Drawing;
using System.Windows.Forms;
public class Form1
{
public void Form1()
{
InitializeComponent();
// initialize the imagelist
ImageList imageList1 = new ImageList();
imageList1.Images.Add("key1", Image.FromFile(@"C:\path\to\file.jpg"));
imageList1.Images.Add("key2", Image.FromFile(@"C:\path\to\file.ico"));
//initialize the tab control
TabControl tabControl1 = new TabControl();
tabControl1.Dock = DockStyle.Fill;
tabControl1.ImageList = imageList1;
tabControl1.TabPages.Add("tabKey1", "TabText1", "key1"); // icon using ImageKey
tabControl1.TabPages.Add("tabKey2", "TabText2", 1); // icon using ImageIndex
this.Controls.Add(tabControl1);
}
}
Run Code Online (Sandbox Code Playgroud)
如果您使用的是WPF:
<TabItem>
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image VerticalAlignment="Center" Source="Icon Imagepath"/>
<TextBlock>Tab header text</TextBlock>
</StackPanel>
</TabItem.Header>
</TabItem>
Run Code Online (Sandbox Code Playgroud)
如果您使用的是WinForms: