WinForms 隐藏 TabControl 标头

编程入门 行业动态 更新时间:2024-10-28 14:31:50
本文介绍了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:关键词]

本文发布于:2023-05-01 11:40:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408904.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WinForms   TabControl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!