简体   繁体   English

在单个表单/窗口中具有多个视图/选项卡的最干净方法

[英]Cleanest Way to Have Multiple Views/Tabs Inside Single Form/Window

My goal is to make an application where, conceptually, everything happens in a single window - a principle most applications I commonly use exhibit, at least for their main interface. 我的目标是创建一个应用程序,从概念上讲,所有事情都在一个窗口中发生-这是我通常使用的大多数应用程序的原理,至少在其主界面上如此。 Installers are a good example of what I am trying to do, where you basically page through the interface. 安装程序是我尝试做的一个很好的例子,您基本上可以在该页面中浏览界面。

You can do this fairly well using a (invisible) tabcontrol. 您可以使用(不可见的)tab控件很好地做到这一点。 This allows you to design the individual tabpages (which are basically forms as far as controls go) in the designer, and you can manually switch between tabpages, and it all takes place inside the same outer form. 这使您可以在设计器中设计各个选项卡页(就控件而言,它们基本上是表格),并且您可以在选项卡页之间手动切换,并且所有这些操作都在同一外部表格中进行。

The problem is, this results in code for everything all in the main form. 问题是,这导致所有形式的代码都以主要形式出现。 What I want is basically the design capabilities of separate forms (drag-and-drop components, only has code for its own controls), but that can be put inside the tabcontrol to get the intended user interface. 我想要的基本上是独立表单的设计功能(拖放式组件,仅具有用于其自己的控件的代码),但是可以将其放在tabcontrol中以获取预期的用户界面。

What is the best way to do this? 做这个的最好方式是什么? I assume there is a clean solution given how common this is. 考虑到这很普遍,我认为有一个干净的解决方案。

Thus far I have followed C# Multiple Screen View Single Form , which works well aside from the fact that all the code ends up in the same class (for example, you need unique names for every single element on the form). 到目前为止,我遵循的是C#多屏幕视图单一表单 ,除了所有代码都归于同一类(例如,表单上每个元素都需要唯一的名称)这一事实之外,它还可以很好地工作。

I think you're looking for UserControls . 我认为您正在寻找UserControls They let you create a "form without a window" if I had to simplify it. 如果我不得不简化它们,它们使您可以创建“没有窗口的表单”。

Once you've built the UserControl, you can then drag and drop it into any Form. 构建UserControl后,可以将其拖放到任何Form中。

You can then replace these controls at runtime as needed. 然后,您可以根据需要在运行时替换这些控件。

See this link for a decent starting tutorial. 请参阅此链接以获取体面的入门教程。 I'll update if I find a better tutorial out there. 如果在那里找到更好的教程,我将进行更新。

http://www.akadia.com/services/dotnet_user_controls.html http://www.akadia.com/services/dotnet_user_controls.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM