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

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).

Related

What is a Tab Control?

In the most basic sense, what is a Tab Control?
I am looking into creating one from scratch (I have many good reasons for this and simply extending existing ones won't make me feel better). But I am not sure how they are made.
Is a Tab Control just a bunch of Panels, inside a main Panel? Here's a picture of what I mean...
At it's core, TabControl is a very simple control. Nothing but a row of rectangles with text on them. It is Winforms that adds the TabPage class, a scrollable container control that adds the ability to hide controls. Derived from the Panel class.
It bulks up with features that you can arbitrarily drop. Like rendering in a way that's compatible with the active visual styles theme that the user selected. And dealing with an app that asks for more tabs than can fit in a row. And implementing both keyboard and mouse navigation. And implementing transparency so the parent window content is visible behind the tabs.
It is so simple that the need to implement your own is rare :)

Visual Studio 2008: Adding components to inherited panel

In this scenario I have a base component with a close button and a flow panel; (FlowLayoutPanel) the idea being that components extending this add their controls to the flow panel and will have the close button functionality done for them.
The problem is that I can't seem to persuade VS to add the components in the subclassed component to the flow panel; this ends up with me having to do so in the code. Which is all well and good except that it won't show up in the designer view. If I add it to the partial class with the designer generated code then I can see the controls in the designer view laid out by the flow panel. But this just gets overwritten afterwards.
Visual Studio doesn't seem to let you dock controls in inherited panels - unless I'm doing something wrong? I did make sure that the base panel is publically visible in case this was the issue.
--
An alternative might be some way to persuade the designer to execute/not overwrite my code in the designer class.
You need to make a ControlDesigner for your control and override the InternalControlDesigner and GetParentForComponent methods.
For an example, open System.Windows.Forms.Design.SplitContainerDesigner (in System.Design.dll in Reflector.

Windows Forms Autosizing in .NET

My C# project contains a form. There are some controls across the top of the form and some controls across the bottom of the form, as well as a FlowLayoutPanel in the center, all of which have been placed with the Visual Studio Form Designer.
During runtime, controls are dynamically added to and removed from the FlowLayoutPanel, and both the panel and the form itself are configured to automatically fit the size of they're contents.
However, since some controls were placed with the designer above and below the FlowLayoutPanel, the desired resizing fails to take place when new controls are added to the FlowLayoutPanel.
Does anybody know of a convenient remedy for this problem?
Anchor the controls you want to move to the side(s) of the form they need to stay the same distance from.
Your best bet might be to put all controls into a 'parent' TableLayoutPanel.

How do I create a workspace window for other windows using c# in visual studio 2008?

I'd like to create a workspace with status bar and menu, and within this workspace container have smaller windows of various types.
For example, if you un-maximise a worksheet in Excel but not the main window, it becomes a window in a larger workspace.
I've tried searching for the result but the main problem is in knowing the right terminology.
You want an MDI (Multiple Document Interface) Form
Just set the IsMdiContainer property of your main form to True, and you should be able to add other forms as mdi children.
Check into MDI programming. Here's a couple links
Creating an MDI Application (CodeProject)
Developing MDI Application in C# (C-Sharp Corner)
On a Windows Forms form, there is the IsMdiContainer property. Setting that will make the form an MDI (multiple document interface) parent. Any window you want to appear as a child of the parent, just set the MdiParent to the form you have IsMdiContainer set to true for. Be aware that WPF does not support MDI. A suggestion may be to try a tabbed interface, like many web browsers have if you're using WPF (or even if you're not).
BTW, Excel doesn't work that way anymore, and I believe Microsoft has pretty much abandoned MDI. Just FYI.
That "workspace" will be ordinary Form instance with IsMdiContainer property set to "true", all inner windows (other instances of the Form class) must have their MdiParent property set to that outer form. You can add status bar and menu (as any other controls) as you do this for any other forms.
"Form.IsMdiContainer Property" article in MSDN have good example on how to use this.

VS 05 - Designer Attributes and Component Designer. How are they related?

I had this answer on another post I asked:
"I believe the VS designer does it [components of a menustrip/statusstrip] by getting an instance of the control's designer (see the Designer attribute), and, if the designer is a ComponentDesigner, getting the AssociatedComponents property."
How do I do this? I'm not even sure where to begin...
The DesignerAttribute attribute can be attached to a Control or Component class in WinForms to indicate the class that implements a designer for visually editing that type of control or component. For example, the Form class has a DesignerAttribute that indicates a class called FormDocumentDesigner implements its designer.
Designers allow special design-time behavior to be applied in the WinForms designer in Visual Studio such as list view column resizing or the sizing handles on controls. Designers that support the addition of child controls to an existing control, such as FormDocumentDesigner are ultimately derived from ComponentDesigner.
You can check this out by using a tool like .NET Reflector.

Categories

Resources