How to change size and image in TabControl

2019-02-25 10:15发布

问题:

I want to change size of TabPage in my TabControl,

each tab should be in one line without scroll.

the second question is about how to change Text into Image like here (Please, ignore the green line):

edit. I used Winforms.

回答1:

Ad 1.

There is no way to adjust width of tab pages to fit width you want automatically, so you just have to do some maths to achieve this.

Ad 2.

First you have to create an ImageList object, which you will then pass to your TabControl:

ImageList il = new ImageList();
il.Images.Add("your_graphics_name", Image.FromFile(@"C:\Graphics\example.png"));
(...)
yourTabControl.ImageList = il;

Then you can set specific image from your image list on your tab page by giving it's key:

yourTabControl.TabPages.Add("title", "text", "your_graphics_name");


回答2:

The size and layout of tabs is quite strictly controlled in WinForms. You can of course change the font and font size which will have an implicit effect on the size of the tabs, but this isn't what you want to do by the sounds of things.

Now apparently Windows does allow you to regulate the minimum default tab width, but you can't do it directly with the out-of-the-box WinForm control. This article explains how: How can i make WinForms TabPage header width fit it's title?.

You may want to consider a 3rd party tab control if this begins to pose a serious problem for you design-wise.



回答3:

Like others said you can't change width of your tabs. But you can make your tabs for example in two rows, if they don't match the screen:

tabControl.Multiline = true;