开发者

Add Inherited Controls to a Panel

I have a base form with two buttons (e.g. OK and Cancel). I want to use a TableLayoutPanel and have the two buttons in it. 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. Designer refuses to add the two buttons to the panel.
  • Adding the TableLayoutPanel in the b开发者_如何学JAVAase form. Can't add controls to the panel from the child form.


In the base form you have to set the property Modifiers = Protected for the TableLayoutPanel and any other control you want to change in the child forms.


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'. Unfortunately, the TableLayoutPanel does not support visual inheritance:

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

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.


Since this hasn't received an answer since almost over a year and WindowsForms is slowly losing against WPF, the answer seems to be "just don't do it".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜