I want to put an icon in the tab header so that this
looks like this.
Add an image to your projectIn Solution Explorer, open the shortcut menu for the project that you want to add the image to, and then choose Add > New Item. In the Add New Item dialog box, under Installed, select Graphics, and then select an appropriate file format for the image.
create an image. set the source of the image to the right file of your resources (e.g. a . png file that you included to your project) drag the image over the button. A text shows that asks you to press ALT to replace the text of the button with the image.
You can do it in the VS Designer this way:
ImageList
property of the TabControl
to the ImageList which contains the icons.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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With