問題描述
如何制作不顯示選項卡標題的選項卡管理器?
How do I make a tab manager that doesn't show the tab headers?
這是一個winforms應用程序,使用標簽管理器的目的是為了顯示內容只能通過代碼來改變.它適用于各種菜單選項更改屏幕內容的菜單.
This is a winforms application, and the purpose of using a tab manager is so the display content can only be changed through code. It's good for menus where various menu options change the screen contents.
推薦答案
在標準 TabControl
上隱藏選項卡非常簡單,只要您知道訣竅.向選項卡控件發送 TCM_ADJUSTRECT
消息當它需要調整標簽大小時,我們只需要捕獲該消息.(我相信這個問題之前已經回答過了,但是發布代碼比搜索更容易.)
Hiding the tabs on a standard TabControl
is pretty simple, once you know the trick. The tab control is sent a TCM_ADJUSTRECT
message when it needs to adjust the tab size, so we just need to trap that message. (I'm sure this has been answered before, but posting the code is easier than searching for it.)
將以下代碼添加到項目中的新類中,重新編譯并使用 CustomTabControl
類而不是內置控件:
Add the following code to a new class in your project, recompile, and use the CustomTabControl
class instead of the built-in control:
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.)
(Code sample originally taken from Dot Net Thoughts.)
請注意,這不適用于位于側面或底部的標簽頁眉.但這不僅看起來很奇怪,而且無論如何您都無法在運行時看到選項卡.只需將它們放在它們所屬的頂部即可.
Note that this will not work properly for tab headers positioned on the sides or the bottom. But not only does that just look weird, you won't be able to see the tabs at run-time anyway. Just put them on the top where they belong.
這篇關于如何創建沒有選項卡標題的 TabControl?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!