.net 如何更改 TabControl 的边框颜色和大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5077891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:18:20  来源:igfitidea点击:

How can I change the border color and size of a TabControl?

.netvb.netwinformstabcontrol

提问by SpongeBob SquarePants

How can I change the border size/style/color of my TabControlto make it blend in with my form's background color?

如何更改我的边框大小/样式/颜色TabControl以使其与表单的背景颜色融合?

I am unable to find any property for this in Visual Studio. Is this possible?

我无法在 Visual Studio 中为此找到任何属性。这可能吗?

采纳答案by Cody Gray

The TabControlisn't expecting to be placed over a custom-colored background. What you're seeing at the edges is the standard color used for 3D controls. You normally wouldn't notice that if you hadn't changed the background color of your form. By default, they're the same color.

TabControl不希望被放置在一个定制的彩色背景。您在边缘看到的是用于 3D 控件的标准颜色。如果您没有更改表单的背景颜色,您通常不会注意到这一点。默认情况下,它们是相同的颜色。

I don't know of any good way to fix this. The TabControldoesn't expose an awful lot of built-in options for customizing its appearance. You're going to have to owner draw and paint it a custom color yourself.

我不知道有什么好方法可以解决这个问题。在TabControl不暴露非常多的内置自定义其外观的选项。您将不得不自己绘制并绘制自定义颜色。

Visit this pagefor some different options and sample code. I suspect that the Completely OwnerDraw TabControlis what you need; use the code that's provided and customize it to your liking. Be thankful someone else has already done all the work for you, because implementing this yourself is non-trivial.

访问此页面以获取一些不同的选项和示例代码。我怀疑Completely OwnerDraw TabControl正是您所需要的;使用提供的代码并根据您的喜好对其进行自定义。感谢其他人已经为你完成了所有的工作,因为你自己实现这一点并非易事。

Also note that changing the DrawModeto "OwnerDrawFixed" will disable themes. Your control will look like it came straight out of Windows 95, instead of getting drawn in the Luna or Aero theme styles. Not a big deal if you're completely customizing how it's painted, but a pain in the rear if all you want is to change the background color.

另请注意,将 更改DrawMode为“OwnerDrawFixed”将禁用主题。您的控件看起来就像直接来自 Windows 95,而不是在 Luna 或 Aero 主题样式中绘制。如果您完全自定义它的绘制方式,这没什么大不了的,但是如果您只想更改背景颜色,则在后面会很痛苦。

回答by Hodroj

if you are trying to hide the borders and blend them with the form's backcolor, put the TabControl in a container like "Panel" control and make the size of the TabConrol bigger than the Panel control size, but this will cover the Tabs Buttons also, and for this issue you can add button for each tab and set the button's click event to to change the TabControl's SelectedTab property. Note: you can keep the TabControl in a location where you can change the tab in designtime then add the small following code on form's Load event to hide the Tabs buttons on runtime:

如果您试图隐藏边框并将它们与窗体的背景色混合,请将 TabControl 放入“Panel”控件之类的容器中,并使 TabConrol 的大小大于 Panel 控件大小,但这也会覆盖 Tabs 按钮,对于这个问题,您可以为每个选项卡添加按钮并将按钮的单击事件设置为更改 TabControl 的 SelectedTab 属性。注意:您可以将 TabControl 保留在可以在设计时更改选项卡的位置,然后在表单的 Load 事件上添加以下小代码以在运行时隐藏选项卡按钮:

Private Sub Form_Load(sender As Object, e As EventArgs) Handles Me.Load

TabControl.ItemSize = New Size(0, 1)
TabControl.SizeMode = TabSizeMode.Fixed

End Sub

回答by Yoko Zunna

Me.TabPage1.BackColor = Color.Blue

Try this, it will be helpful to you.

试试这个,它会对你有帮助。