加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何将图标或图像添加到Visual Studio 2010中的选项卡

发布时间:2020-12-15 06:55:06 所属栏目:百科 来源:网络整理
导读:我想在标签页上放一个图标,以便 this 看起来像this. 解决方法 您可以通过以下方式在VS Designer中执行此操作: 将ImageList添加到您的表单. 将TabControl的ImageList属性设置为包含图标的ImageList. 将TabControl中每个TabPage的ImageIndex或ImageKey属性设
我想在标签页上放一个图标,以便 this

看起来像this.

解决方法

您可以通过以下方式在VS Designer中执行此操作:

>将ImageList添加到您的表单.
>将TabControl的ImageList属性设置为包含图标的ImageList.
>将TabControl中每个TabPage的ImageIndex或ImageKey属性设置为要显示的所需图像.

如果你想在代码中做所有这一切,这里是如何去做的.

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:pathtofile.jpg"));
        imageList1.Images.Add("key2",Image.FromFile(@"C:pathtofile.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);
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读