Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 base form. Can't add controls to the panel from the child form.
like image 690
Johannes Rudolph Avatar asked Jan 22 '23 14:01

Johannes Rudolph


2 Answers

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.

like image 130
Argons Avatar answered Jan 31 '23 16:01

Argons


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.

like image 38
Paccc Avatar answered Jan 31 '23 17:01

Paccc