c#:如何删除tabcontrol边界
本文关键字:删除 tabcontrol 边界 何删除 | 更新日期: 2023-09-27 17:59:29
在我的表单中,我使用了一个tabcontrol。我想同时隐藏选项卡标题和边框。我可以做任何一种,如果我试图隐藏标题,那么边框就会变得可见。有人能帮我吗?谢谢,这是我的代码:
public Form3()
{
InitializeComponent();
this.NativeTabControl1 = new NativeTabControl();
this.NativeTabControl1.AssignHandle(this.tabControl1.Handle);
}
private NativeTabControl NativeTabControl1;
private class NativeTabControl : NativeWindow
{
protected override void WndProc(ref Message m)
{
if ((m.Msg == TCM_ADJUSTRECT))
{
RECT rc = (RECT)m.GetLParam(typeof(RECT));
//Adjust these values to suit, dependant upon Appearance
rc.Left -= 3;
rc.Right += 3;
rc.Top -= 3;
rc.Bottom += 3;
Marshal.StructureToPtr(rc, m.LParam, true);
}
base.WndProc(ref m);
}
private const Int32 TCM_FIRST = 0x1300;
private const Int32 TCM_ADJUSTRECT = (TCM_FIRST + 40);
private struct RECT
{
public Int32 Left;
public Int32 Top;
public Int32 Right;
public Int32 Bottom;
}
private void Form3_Load(object sender, EventArgs e)
{
//hides tabcontrol headers
tabControl1.Appearance = TabAppearance.Buttons;
tabControl1.ItemSize = new Size(0, 1);
tabControl1.SizeMode = TabSizeMode.Fixed;
}
}
Stackoverflow上还有另一个线程,它提供了一些在Windows窗体中隐藏TabControl
的选项卡行的想法
我最喜欢的方法是覆盖WndProc
并将Multiline
属性设置为true
。
public partial class TabControlWithoutHeader : TabControl
{
public TabControlWithoutHeader()
{
if (!this.DesignMode) this.Multiline = true;
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x1328 && !this.DesignMode)
m.Result = new IntPtr(1);
else
base.WndProc(ref m);
}
}
我在Windows8.1上测试了代码,既没有看到标签,也没有看到边框。所以我认为你不需要像你发布的那样使用代码。
我通常建议在xaml而不是C#中执行此操作(我是一名WPF开发人员)。我相信您也可以在C#中通过命名TabControl和每个Tab本身来执行此操作。
tabControlName.BorderBrush = null;
///^Gets rid of the TabControl's border.
tabName1.Height = 0;
tabName2.Height = 0;
tabNameETC.Height = 0;
///^Removes the tabs(headers) if you have the TabControl.TabStripPlacement set to left
/// or right, then use the following instead:
tabName1.Width = 0
tabName2.Width = 0
tabNameETC.Width = 0