简体   繁体   English

如何在TabControl中更改大小和图像

[英]How to change size and image in TabControl

I want to change size of TabPage in my TabControl , 我想在TabControl更改TabPage大小, 在此输入图像描述

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. 我使用Winforms。

Ad 1. 广告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. 广告2。

First you have to create an ImageList object, which you will then pass to your TabControl : 首先,您必须创建一个ImageList对象,然后将其传递给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");

The size and layout of tabs is quite strictly controlled in WinForms. 在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. 现在显然Windows允许您规范最小的默认选项卡宽度,但是您不能直接使用开箱即用的WinForm控件。 This article explains how: How can i make WinForms TabPage header width fit it's title? 本文解释了如何: 如何使WinForms TabPage标题宽度适合它的标题? .

You may want to consider a 3rd party tab control if this begins to pose a serious problem for you design-wise. 如果这开始在设计方面造成严重问题,您可能需要考虑第三方选项卡控件。

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM