如何将图标或图像在Visual Studio 2010中添加一个标签 [英] How to add an icon or image to a tab in Visual Studio 2010

查看:767
本文介绍了如何将图标或图像在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:


  1. 添加一个ImageList到表单中。

  2. 设置的的ImageList 属性的TabControl 来包含图标的ImageList。

  3. 的ImageIndex ImageKey 每个的TabPage 中的TabControl到要显示所需图像的属性。

  1. Add an ImageList to your form.
  2. Set the ImageList property of the TabControl to the ImageList which contains the icons.
  3. Set the ImageIndex or ImageKey property of each TabPage 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆