WinForms 选项卡控件问题 [英] WinForms Tab Control question

查看:31
本文介绍了WinForms 选项卡控件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以两种模式显示的表单.如果您使用选项卡控件并且每个选项卡上的控件布局不同,那么切换模式会完全改变表单的外观.

I have a form that displays in two modes. Switching modes completely changes the appearance of the form much like you would expect if you were using a tab control and had a different layout of controls on each tab.

如果我可以隐藏选项卡本身,那么选项卡控件将是完美的.

A tab control would be perfect if I could hide the tab itself.

当然,我可以使用两个面板并以编程方式显示和隐藏适当的面板.我试过了,但我的锚定一直搞砸了(我认为这是 Visual Studio 设计器的错误.)

Of course, I could use two panels and pro grammatically show and hide the appropriate panels. I tried this, but my anchoring keeps on getting messed up (I think it is a Visual Studio designer bug.)

理想情况下,我想使用无选项卡的向导"控件,并在设计时绘制第一页的控件,将PageNumber"属性切换到第二页,然后将控件拖放到第二页.

Ideally, I'd like to use a "wizard" control, which is tab-less, and at designtime, draw the controls for the first page, switch the "PageNumber" property to page two, and then drop controls onto the second page.

我认为 TabControl 具有无需选项卡即可显示的功能,例如,这非常适合创建向导风格的界面.

I thought the TabControl had functionality to appear without tabs, which would lend itself nicely to creating a Wizard style interface, for example.

这样做的最佳方法是什么,以便我的设计时外观模仿运行时?

What's the best way to do this so that my design time appearance mimics the run-time?

目前,我有 2 个面板,一个直接在另一个面板上,我触发了每个面板的可见属性,我的自动锚定被 VS 搞砸了.我可能不得不求助于编写自己的 archoring 代码,这并不难,但我喜欢它,因为设计环境对运行时屏幕外观的反应尽可能接近.它只是让生活更轻松.

At the moment, I have 2 panels, one directly over the other and I flip-flop the visible property of each and my auto anchoring is getting all messed up by VS. I may have to resort to writing my own archoring code, which isnt hard, but I like it when the design env reacts as closely as possibility to how the screen will look when it runs. It just makes life easier.

我也有 Telerik Q3 WinForm 控件,以防该控件集中有替代...

I have Telerik Q3 WinForm controls, too, in case there is an alternative in that control set...

建议?

推荐答案

这是可能的.向您的项目添加一个新类并粘贴如下所示的代码.编译.将新控件从工具箱顶部拖放到表单上.它在设计时具有选项卡,因此您可以轻松地在页面之间切换.但是在运行时隐藏它们,在代码中使用 SelectedIndex 或 SelectedTab 属性来切换视图.

It's possible. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form. It has tabs at design time so you can easily switch between pages. But hides them at runtime, use the SelectedIndex or SelectedTab property in your code to switch views.

using System;
using System.Windows.Forms;

class PageControl : TabControl {
  protected override void WndProc(ref Message m) {
    // Hide tabs by trapping the TCM_ADJUSTRECT message
    if (m.Msg == 0x1328 && !DesignMode) m.Result = (IntPtr)1;
    else base.WndProc(ref m);
  }
}

这篇关于WinForms 选项卡控件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆