如何创建没有选项卡标题的 TabControl?
如何制作不显示选项卡标题的选项卡管理器?
这是一个winforms应用程序,使用选项卡管理器的目的是只能通过代码更改显示内容。它非常适合各种菜单选项更改屏幕内容的菜单。
How do I make a tab manager that doesn't show the tab headers?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
一旦您了解了技巧,隐藏标准
TabControl
上的选项卡就非常简单。向选项卡控件发送TCM_ADJUSTRECT
消息当它需要调整选项卡大小时,我们只需要捕获该消息即可。 (我确信之前已经回答过这个问题,但是发布代码比搜索它更容易。)将以下代码添加到项目中的新类中,重新编译,然后使用
CustomTabControl
类内置控件的:(代码示例最初取自Dot Net Thoughts。)
请注意对于位于侧面或底部的选项卡标题,这将无法正常工作。但这不仅看起来很奇怪,而且您无论如何也无法在运行时看到选项卡。只需将它们放在它们所属的顶部即可。
Hiding the tabs on a standard
TabControl
is pretty simple, once you know the trick. The tab control is sent aTCM_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.)Add the following code to a new class in your project, recompile, and use the
CustomTabControl
class instead of the built-in control:(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.
是的,如果它是 Web 应用程序,您可以使用相同的位置构建自己的 DIV,并根据您的需要隐藏/显示。
Right, if it's web application, you can build your own DIV with the same placement and hide/show as per your needs.
和其他人一样,我发现你的问题有点令人困惑。我之前使用过此处找到的方法。使用这种方式,您可以更改一个属性来决定是否要显示选项卡标题。
Along with everybody else, I find your question a bit confusing. I've used this method found here before. Using this way you have a single property you can change as to whether you want to show the tab headers or not.
在编辑和评论使问题更加清晰之后,我认为处理此问题的正常方法是使用多个面板而不是选项卡。
After the edit and comments made the question more clear, I think the normal way to handle this is to use multiple panels rather than tabs.
我想,使用面板是最简单的解决方案。此外,我建议使用我的(免费、开源)
VisualStateManager
来简化切换并消除大量.Enabled = true
的问题。软件包在 Nuget 上可用。
只需编写这段代码:
I guess, that using panels is the simplest solution. In addition, I suggest using my (free, opensource)
VisualStateManager
to simplify switching and eliminate lots of.Enabled = true
horrors.Package is available on Nuget.
Just write this code: