在设计时向 TabPage 添加控件的标准方法是什么?

发布于 2024-08-22 17:41:09 字数 667 浏览 6 评论 0原文

我正在创建我的第一个 Windows 窗体应用程序,要部署在 Windows Mobile 上,但在设计选项卡式界面时遇到了一些问题。

我假设我可以创建一个 TabControl,然后添加一些 TabPage,然后依次将 Control 拖到每个选项卡页上。这似乎不可能,我在网上看到的大多数信息似乎都表明应该在运行时动态添加控件。

我在这里遗漏了一些明显的东西还是这确实是正确的?

如果您确实必须在运行时添加控件,那么人们通常如何管理设计过程。他们是否为每个选项卡创建一个自定义用户控件,然后在运行时添加它?

设计环境(C# Visual Studio 2005、.net 2.0) 运行时环境 (Windows Mobile 6.1)

更新 1

在 Visual Studio 中执行的实际步骤如下:-

  1. 选择“新建项目”->“智能设备-> Windows Mobile 6 专业版 ->设备应用程序
  2. 向 Form1 添加了 TabControl。这会自动添加 tabPage1 和 tabPage2

Update 2

这个问题的解决方案是令人尴尬的菜鸟。 TabControl 将选项卡放在页面底部,我做的第一件事是将选项卡控件的大小调整为单行,然后隐藏 TabPage 控件。

I am creating my first Windows Forms application, to be deployed on Windows Mobile and I am having some trouble designing a Tabbed Interface.

I had assumed that I could Create a TabControl, then Add some TabPages and then drag Controls on to each Tab Page in turn. This does not appear to be possible and most of the information I see on the web seems to suggest that the controls should be added dynamically at run-time.

Am I missing something obvious here or is this indeed correct?

If you do have to add the controls at runtime then how do people generally manage the design process. Do they create a Custom UserControl for each tab and then add that at runtime?

Design environment (C# Visual Studio 2005, .net 2.0)
Runtime environment (Windows Mobile 6.1)

Update 1

The actual steps taken within visual studio were as follows :-

  1. Select New Project -> SmartDevice -> Windows Mobile 6 Professional -> Device Application
  2. Added a TabControl to Form1. This automatically adds tabPage1 and tabPage2

Update 2

The solution to this is embarrassingly noobish. The TabControl puts the tabs at the bottom of the page, the first thing I was doing was resizing the tab control to a single line which was then hiding the TabPage control.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゞ记忆︶ㄣ 2024-08-29 17:41:09

目前我不使用 Windows Mobile,但我认为它的工作原理完全相同。

TabControl 添加到表单后,您应该查看属性并搜索 TabPages。在这里,您可以向控件添加和删除新的 TabPage,并在设计器中按照您的喜好进行设计。

对于您关于在每个 TabPage 上使用 UserControls 的问题,我肯定会说。这样可以更轻松地区分每个页面以及每个页面上将发生的情况。

另外,在最后一步,我将把所需的代码从 Designer.cs 移到我自己的函数中(例如 var tabControl = CreateTabControl() ,其中设置了我的所有属性。然后我将所有我的 UserControls 放入

private IEnumerable<Type> GetAllTypes()
{
    yield return typeof(MyFirstControl);
    yield return typeof(MySecondControl);
}

并创建

private void CreateTabPages(TabControl tabControl, IEnumerable<Type> types)
{
    foreach(var type in types)
    {
        var control = Activator.CreateInstance(type);
        var tabPage = new TabPage();
        tabPage.Controls.Add(control);
        tabControl.TabPages.Add(tabPage);
    }
}

一个,然后将被调用

CreateTabPages(tabControl, GetAllTypes());

通过这种方法,我可以轻松地使用一行代码添加另一个选项卡页,并在其自己的范围内设计它。

Currently i don't use Windows Mobile, but i think it works quite the same.

After adding a TabControl to your form you should take a look into the properties and search for TabPages. Here you can add and delete new TabPages to your Control and design it as you like in the designer.

To your question about using UserControls on each TabPage i would definitely say Yes. It makes easier to separate between each page and what will happen on each one.

Also at a last step i am going to move the needed code out of the Designer.cs into my own function (e.g. var tabControl = CreateTabControl() where all of my properties are set. Then i put all my UserControls into an

private IEnumerable<Type> GetAllTypes()
{
    yield return typeof(MyFirstControl);
    yield return typeof(MySecondControl);
}

and make an

private void CreateTabPages(TabControl tabControl, IEnumerable<Type> types)
{
    foreach(var type in types)
    {
        var control = Activator.CreateInstance(type);
        var tabPage = new TabPage();
        tabPage.Controls.Add(control);
        tabControl.TabPages.Add(tabPage);
    }
}

this will then be called by

CreateTabPages(tabControl, GetAllTypes());

With this approach i can easily add another Tab Page with a single line of code and design it in its own scope.

祁梦 2024-08-29 17:41:09

我刚刚打开vs2008并创建了一个tabcontrol,然后我在设计器中使用拖放添加了控件,我没有发现任何问题。

我用来执行此操作的方法是为每个选项卡创建一个用户控件,但我将用户控件添加到设计器中的选项卡中。 (请注意,在生成解决方案之前,用户控件不会出现在工具箱中)。

我不知道为什么你的方法不起作用。在尝试添加控件之前您是否停止了应用程序?

祝你好运。

I just opened vs2008 and created a tabcontrol, then I added controls inside using drag and drop in the designer and I didn't found any problem.

The way I use to do it is to create a usercontrol for each tab, But I add the usercontrol to the tab in the designer. (note that the usercontrol will not appear in the toolbox until you generate your solution).

I didn't know why your method are not working. Did you stop your application before try to add the controls?

Good Luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文