简体   繁体   English

将继承的控件添加到面板

[英]Add Inherited Controls to a Panel

I have a base form with two buttons (eg OK and Cancel). 我有一个带有两个按钮的基本表单(例如,确定和取消)。 I want to use a TableLayoutPanel and have the two buttons in it. 我想使用TableLayoutPanel并在其中包含两个按钮。 Child forms should be able to add more controls to the table as well as modify its layout itself via the designer. 子窗体应该能够向表添加更多控件,并通过设计器修改其布局本身。

So far I can't get this to work. 到目前为止,我无法使它正常工作。 I have tried the following: 我尝试了以下方法:

  • Adding the TableLayoutPanel to the child form. TableLayoutPanel添加到子窗体。 Designer refuses to add the two buttons to the panel. Designer拒绝将两个按钮添加到面板。
  • Adding the TableLayoutPanel in the base form. 在基本表单中添加TableLayoutPanel Can't add controls to the panel from the child form. 无法从子窗体向面板添加控件。

在基本表单中,必须为TableLayoutPanel设置属性Modifiers = Protected,并在子表单中设置要更改的任何其他控件。

The reason why you cant edit your TableLayoutPanel in the derived class is because you are attempting to use a feature of WinForms called 'visual inheritance'. 您不能在派生类中编辑TableLayoutPanel的原因是,您正在尝试使用WinForms的“可视继承”功能。 Unfortunately, the TableLayoutPanel does not support visual inheritance: 不幸的是, TableLayoutPanel不支持视觉继承:

http://msdn.microsoft.com/en-us/library/ms171689.aspx (read at the bottom of the page) http://msdn.microsoft.com/en-us/library/1z3efhd2.aspx http://msdn.microsoft.com/zh-CN/library/ms171689.aspx (在页面底部阅读) http://msdn.microsoft.com/zh-cn/library/1z3efhd2.aspx

This is why it appears blocked in the inherited controls. 这就是为什么它在继承的控件中似乎被阻止的原因。 I am not sure why they do not support this feature, but I have recently come across the same problem and ended up having to solve the problem another way. 我不确定为什么他们不支持此功能,但是最近我遇到了同样的问题,最终不得不以另一种方式解决该问题。

由于这已经有将近一年的时间了,而且WindowsForms在对抗WPF方面正在缓慢失败,因此答案似乎是“只是不做”。

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

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