How to change size and image in TabControl

2019-02-25 09:45发布

I want to change size of TabPage in my TabControl,enter image description here

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):

enter image description here

edit. I used Winforms.

3条回答
甜甜的少女心
2楼-- · 2019-02-25 10:03

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;
查看更多
3楼-- · 2019-02-25 10:19

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.

查看更多
一纸荒年 Trace。
4楼-- · 2019-02-25 10:22

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");
查看更多
登录 后发表回答