在 Windows 窗体中向 SplitContainer 添加面板 [英] Adding panels to SplitContainer in Windows Forms

查看:45
本文介绍了在 Windows 窗体中向 SplitContainer 添加面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到有关如何将面板添加到 SplitContainer 的文档.我可以很好地创建 SplitContainer,但我不能将我编码的面板放在 splitcontainer 内.

I'm having trouble finding the documentation on how to add panels to a SplitContainer. I can create the SplitContainer fine, but I can't put the panels I've coded inside of the splitcontainer.

我尝试过

sc.Container.Add(myPanel);
sc.Container.Add(myOtherPanel);

但是 Container 始终为 null.有谁知道我做错了什么?

But Container is always null. Does anyone know what I'm doing wrong?

推荐答案

SplitContainer 总是包含两个面板,你不能改变它!(而且您不需要自己添加任何面板.)

The SplitContainer always contains two panels and you cannot change that! (And you don't need to add any panels yourself.)

您可以通过属性Panel1Panel2 访问这两个面板.

You can access the two panels through the properties Panel1 and Panel2.

如果您需要更多面板,您可以嵌套多个 SplitContainers.

If you need more panels, you can however nest several SplitContainers.

更新

您无法替换现有面板.您可以做的是,将您自己的控件放在现有的拆分容器面板上(您的控件也可以是包含其他控件或用户定义控件的 System.Windows.Forms.Panels):

You cannot replace the existing panels. What you can do, is to place your own controls on the existing split container panels (and your controls can also be System.Windows.Forms.Panels containing other controls or user defined controls):

sc.Panel1.Controls.Add(myPanel);
sc.Panel2.Controls.Add(myOtherPanel);

myPanel.Dock = DockStyle.Fill;
myOtherPanel.Dock = DockStyle.Fill;

当然,如果您没有必须动态添加控件的场景,您也可以使用 Visual Studio 的表单设计器添加它们.如果您创建自己的控件,它们将自动出现在同一项目内的工具箱中,您只需将它们拖放到 SplitContainer 的面板上即可.

Of course you can add them using the forms designer of Visual Studio of as well, if you don't have a scenario where you have to add controls dynamically. If you create your own controls, they will automatically appear in the Toolbox inside of the same project and you can just drag and drop them on the SplitContainer's panels.

这篇关于在 Windows 窗体中向 SplitContainer 添加面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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