本文介绍了WinForms 隐藏 TabControl 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我需要一些方法来隐藏 TabControl 的标题(我将以编程方式切换选定的选项卡).我该怎么做?
I need some way to hide the headers of a TabControl (I'll be switching the selected tab programatically). How can I do this?
推荐答案
将 tabcontrol 放在面板中并固定它以隐藏标题.最简单的方法是在后面的代码中执行此操作(或创建执行此操作的自定义控件):
Put the tabcontrol in a panel and fixate it so it hides the headers. Easiest is to do it in the code behind (or create a custom control that does this):
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim bordersize As Integer = 3 'could'nt find this on the control.
Dim ControlSize As New Size(437, 303) ' the size you want for the tabcontrol
Dim ControlLocation As New Point(10, 10) 'location
Dim p As New Panel
p.Size = ControlSize
p.Location = ControlLocation
Me.Controls.Add(p)
Dim t As New TabControl
t.Size = ControlSize
p.Controls.Add(t)
t.Left = -t.Padding.Y
t.Top = -(t.ItemSize.Height + t.Padding.Y)
p.Width = t.Width - t.Padding.X
p.Height = t.Height - (t.ItemSize.Height + t.Padding.Y + bordersize)
t.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top
AddHandler t.GotFocus, AddressOf ignoreFocus
End Sub
Private Sub ignoreFocus(ByVal sender As Object, ByVal e As System.EventArgs)
Dim t As TabControl = CType(sender, TabControl)
If t.SelectedIndex > -1 Then t.TabPages(t.SelectedIndex).Focus()
End Sub
现在,如果您调整面板的大小,tabcontrol 将跟随并且只显示 tabpage-area.
Now, if you resize the panel, the tabcontrol will follow and only show the tabpage-area.
这篇关于WinForms 隐藏 TabControl 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论