I’m trying to add an image on window form using c#, but every implementation did not give the result I needed. I want the image stay on the navigation bar, but it always hop into the main tab. This is the code I’m currently using
public TabPage AddCustomTabs()
{
TabPage imageTab = new TabPage();
imageTab.Text = "";
PictureBox pictureBox = new PictureBox();
pictureBox.Image = Image.FromFile(@"gameBarResources\kakumei.png");
pictureBox.Dock = DockStyle.Fill;
// Add the picture box to the tab page
imageTab.Controls.Add(pictureBox);
// Add the tab page to the tab control
_tabControl.TabPages.Add(imageTab);
return imageTab;
}
The image supposed to be at the navigation bar (The pink area)
>Solution :
- Add an
ImageList
to your form and add it images. Set the image size. - Set the TabControl’s
ImageList
property to your image list (e.g.imageList1
). - Click on a tab page and set the
ImageIndex
or theImageKey
property. There is a drop-down in the properties window, where you can select an image from the ImageList.
You can also change the ItemSize
of the TabControl. This defines the size of the tabs (navigation part of the tab page).