在设计时向 TabPage 添加控件的标准方法是什么?
我正在创建我的第一个 Windows 窗体应用程序,要部署在 Windows Mobile 上,但在设计选项卡式界面时遇到了一些问题。
我假设我可以创建一个 TabControl,然后添加一些 TabPage,然后依次将 Control 拖到每个选项卡页上。这似乎不可能,我在网上看到的大多数信息似乎都表明应该在运行时动态添加控件。
我在这里遗漏了一些明显的东西还是这确实是正确的?
如果您确实必须在运行时添加控件,那么人们通常如何管理设计过程。他们是否为每个选项卡创建一个自定义用户控件,然后在运行时添加它?
设计环境(C# Visual Studio 2005、.net 2.0) 运行时环境 (Windows Mobile 6.1)
更新 1
在 Visual Studio 中执行的实际步骤如下:-
- 选择“新建项目”->“智能设备-> Windows Mobile 6 专业版 ->设备应用程序
- 向 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 :-
- Select New Project -> SmartDevice -> Windows Mobile 6 Professional -> Device Application
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前我不使用 Windows Mobile,但我认为它的工作原理完全相同。
将
TabControl
添加到表单后,您应该查看属性并搜索TabPages
。在这里,您可以向控件添加和删除新的 TabPage,并在设计器中按照您的喜好进行设计。对于您关于在每个 TabPage 上使用 UserControls 的问题,我肯定会说是。这样可以更轻松地区分每个页面以及每个页面上将发生的情况。
另外,在最后一步,我将把所需的代码从 Designer.cs 移到我自己的函数中(例如
var tabControl = CreateTabControl()
,其中设置了我的所有属性。然后我将所有我的UserControls
放入并创建
一个,然后将被调用
通过这种方法,我可以轻松地使用一行代码添加另一个选项卡页,并在其自己的范围内设计它。
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 forTabPages
. 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 myUserControls
into anand make an
this will then be called by
With this approach i can easily add another Tab Page with a single line of code and design it in its own scope.
我刚刚打开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.