简体   繁体   中英

Visual Inheritance - Add controls at designer to a Panel hosted in TableLayoutPanel

I'm making a base form (WinForm) to use like a blueprint for my general form design, I want the panel (P_Content in the screenshot) to be where controls are put in the Child Forms.

But said P_Content is locked in the child forms, adding controls in the code obviously works but it does not in Design View.

The panel is public and so is its parent containers ( TableLayoutPanel ).

This seems really basic but I can't seem to find any answer why this is happening.

P_Content being the big empty space.

截图

Its seems you have hosted the Panel in a TableLayoutPanel . According to the documentations you should avoid visual inheritance for TableLayoutPanel :

The TableLayoutPanel control does not support visual inheritance in the Windows Forms Designer. A TableLayoutPanel control in a derived class appears as "locked" at design time.

The behavior is not limited to TableLayoutPanel and it's documented that some other controls also do not support visual inheritance from the base form and will be always read-only and appear as locked in the inherited form regardless of the modifiers you use:

Not all controls support visual inheritance from a base form. The following controls do not support the scenario described in this walkthrough:

  • WebBrowser
  • ToolStrip
  • ToolStripPanel
  • TableLayoutPanel
  • FlowLayoutPanel
  • DataGridView

These controls in the inherited form are always read-only regardless of the modifiers you use (private, protected, or public).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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