如何将图标或图像在Visual Studio 2010中添加一个标签 [英] How to add an icon or image to a tab in Visual Studio 2010
本文介绍了如何将图标或图像在Visual Studio 2010中添加一个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想提出一个图标的选项卡标题,这样这
I want to put an icon in the tab header so that this
结果
看起来像的this 。
推荐答案
您可以这样做在VS设计师:
You can do it in the VS Designer this way:
- 添加一个ImageList到表单中。
- 设置的
的ImageList
属性的TabControl
来包含图标的ImageList。 - 将
的ImageIndex
或ImageKey
每个的TabPage
中的TabControl到要显示所需图像的属性。
- Add an ImageList to your form.
- Set the
ImageList
property of theTabControl
to the ImageList which contains the icons. - Set the
ImageIndex
orImageKey
property of eachTabPage
in the TabControl to the desired image you want to display.
如果您想要做这一切的代码,这里是如何去做。
If you'd like to do it all in code, here's how to go about it.
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);
}
}
这篇关于如何将图标或图像在Visual Studio 2010中添加一个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文