C# Exercises

Home AgriMetSoft About Contact

How to Use ImageList in Header of Tabpage in C# | Visual Studio

	    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TabControl_ImageList
{
  public partial class Form1 : Form
  {
    ImageList imageList;
    TabPage pgeBox;
    TabPage pgeFaceBook;
    TabPage pgeTw;
    TabControl tabControl1;
    public Form1()
    {
      InitializeComponent();

      Text = "TabControl Image Icons";
      StartPosition = FormStartPosition.CenterScreen;

      tabControl1 = new TabControl();
      tabControl1.Location = new Point(14, 16);
      tabControl1.Size = new Size(310, 170);
      tabControl1.HotTrack = true;
      tabControl1.Appearance = TabAppearance.FlatButtons;

      imageList = new ImageList();
      imageList.Images.Add(Image.FromFile(@"E:\icn1.png"));
      imageList.Images.Add(Image.FromFile(@"E:\icn2.png"));
      imageList.Images.Add(Image.FromFile(@"E:\icn3.png"));
      tabControl1.ImageList = imageList;
      pgeBox = new TabPage();
      pgeBox.Text = "BoxPlot";
      pgeBox.ImageIndex = 1;
      tabControl1.Controls.Add(pgeBox);

      pgeFaceBook = new TabPage();
      pgeFaceBook.Text = "FaceBook";
      pgeFaceBook.ImageIndex = 2;
      tabControl1.TabPages.Add(pgeFaceBook);

      pgeTw = new TabPage();
      pgeTw.Text = "twitter";
      pgeTw.ImageIndex = 0;
      tabControl1.TabPages.Add(pgeTw);
      Controls.Add(tabControl1);

      tabControl1.TabPages[0].BackgroundImage = imageList.Images[0];
      tabControl1.TabPages[0].BackgroundImageLayout = ImageLayout.Center;
      tabControl1.TabPages[1].BackgroundImage = imageList.Images[1];
      tabControl1.TabPages[1].BackgroundImageLayout = ImageLayout.Center;
      tabControl1.TabPages[2].BackgroundImage = imageList.Images[2];
      tabControl1.TabPages[2].BackgroundImageLayout = ImageLayout.Center;
    }

  }
}

		
	 


Download the project of Visual Studio 2013 in DropBox Download


How to use Imagelist in Tabcontrol Header | Winforms C#


List of Exercises