如何制作不显示标题页的标签管理器?
这是一个winforms应用程序,使用选项卡管理器的目的是只能通过代码更改显示内容。这对于各种菜单选项改变屏幕内容的菜单很有用。
答案 0 :(得分:15)
一旦你知道了诀窍,隐藏标准TabControl
上的标签就非常简单了。当需要调整选项卡大小时,选项卡控件将发送TCM_ADJUSTRECT
message,因此我们只需要捕获该消息。 (我确信之前已经回答过,但发布代码比搜索代码更容易。)
将以下代码添加到项目中的新类,重新编译,并使用CustomTabControl
类而不是内置控件:
class CustomTabControl : TabControl
{
private const int TCM_ADJUSTRECT = 0x1328;
protected override void WndProc(ref Message m)
{
// Hide the tab headers at run-time
if (m.Msg == TCM_ADJUSTRECT && !DesignMode)
{
m.Result = (IntPtr)1;
return;
}
// call the base class implementation
base.WndProc(ref m);
}
}
(代码示例最初取自Dot Net Thoughts。)
请注意,对于位于侧面或底部的标签页眉,这将无法正常工作。但这不仅看起来很奇怪,而且无论如何都无法在运行时看到标签。把它们放在它们所属的顶部。
答案 1 :(得分:1)
是的,如果是网络应用程序,您可以使用相同的位置构建自己的DIV,并根据需要隐藏/显示。
答案 2 :(得分:1)
与其他人一起,我发现你的问题有点令人困惑。我之前使用过here这个方法。使用这种方式,您可以更改一个属性,以确定是否要显示选项卡标题。
答案 3 :(得分:0)
在编辑和评论使问题更加清晰之后,我认为处理这个问题的正常方法是使用多个面板而不是标签。
答案 4 :(得分:0)
我猜,使用面板是最简单的解决方案。另外,我建议使用我的(免费,开源)VisualStateManager
来简化切换并消除大量.Enabled = true
恐怖。
包可用on Nuget。
只需编写此代码:
// Contains and propagates information about current page
private SwitchCondition<int> settingPageCondition;
// Controls state of specific controls basing on given SwitchCondition
private VisualStateSwitchController<int> settingPageController;
// (...)
private void InitializeActions()
{
// Initialize with possible options
settingPageCondition = new SwitchCondition<int>(0, 1);
settingPageController = new VisualStateSwitchController<int>(
null, // Enabled is not controlled
null, // Checked is not controlled
settingPageCondition, // Visible is controller by settingPageCondition
new SwitchControlSet<int>(0, pGeneral), // State 0 controls pGeneral
new SwitchControlSet<int>(1, pParsing)); // State 1 controls pParsing
}
// (...)
public void MainForm()
{
InitializeComponent();
InitializeActions();
}
// (...)
// Wat to set specific page
settingPageCondition.Current = 0;