在面板上使用 C# WinForms Designer 而不是 Form?

发布于 2024-07-14 22:52:52 字数 416 浏览 5 评论 0原文

警告:我是用 C# 构建 GUI 的新手(来自 Java 中 Swing 和 SWT 的悠久历史。)

使用 VS2008,当我创建一个新类并扩展 System.Windows.Forms.Form,WinForms Designer 工作得非常好。 然而; 当我创建一个新类并扩展 System.Windows.Forms.Panel 时,设计器的工作方式并不那么优雅 - 它只是显示了包含在组件中的某种抽象的列表类型视图。面板(而不是在面板中显示控件的实际布局。)

有没有办法让设计器更好地使用面板?

或者是否有一些解决方法,以便我可以与设计器一起构建一个表单,然后将其用作一个面板?

我真正想要的是一些我可以与设计器一起构建的 UI“元素”,然后动态(阅读:以编程方式)将该“元素”添加/删除到更大的 UI。

Warning: I'm new to GUI building in C# (come from a long history in Java with Swing and SWT.)

Using VS2008, When I create a new class, and extend System.Windows.Forms.Form, the WinForms Designer works really nicely. However; when I create a new class and extend System.Windows.Forms.Panel, the designer does not work nearly as elegantly - it simply shows some kind of abstract, list-type view of the components contained in the Panel (as opposed to showing the actual layout of the Controls in the Panel.)

Is there a way to get the Designer to work more nicely with a Panel?

Or is there some workaround so that I can build a Form with the designer, and then use it as if it were only a Panel?

What I'm really looking for is some UI 'element' I can build with the designer, and then dynamically (read: programmatically) add/remove that 'element' to a larger UI.

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

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

发布评论

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

评论(1

清醇 2024-07-21 22:52:52

我认为您正在寻找的是 用户控件。 您可以直接继承它,并且应该能够使用设计器在其上拖放内容。

为了使其更容易,您只需右键单击您的项目并单击“添加”->“添加”即可。 用户控制。 这将为您创建 .cs 文件以及设计器生成的代码的部分 .cs 文件。

I think what you're looking for is a UserControl. You can inherit directly from that, and you should be able to use the designer to drag and drop stuff on it.

To make it even easier, you can just right click on your project and click Add -> User Control. That will create the .cs file for you as well as a partial .cs file for the designer generated code.

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