Visual Studio 2008: Adding components to inherited panel - c#

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.

Related

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

C# WindowsForms UserControl's Controls Designer Support

What I am looking for is the same type of designer support for controls inside a usercontrol. ie - resizing a textbox, moving a label, that are inside a usercontrol after placeing the usercontrol on to a form.
What I've been able to do...
create a usercontrol
use the designer to add controls to the it
create a new window forms app
add the usercontrol to the toolbox
drag and drop the control on the a form
where I am stuck...
edit the usercontrols controls. IE - being able to resize a textbox that is inside the usercontrol using the designer.
I found a similar question on stack that was never answered. So if I am being too vague you can follow this link https://stackoverflow.com/questions/10359772/example-make-constituent-controls-in-a-usercontrol-editable.
Thank you.
After reading Nikita's comment I was able to find Microsoft support page on creating a custom designer for controls.
Here's a quote if your interested on how the designed-time support works
The design-time support for components in the .NET Framework, however, is not defined exclusively by a design tool such as Microsoft Visual Studio .NET. Rather, the development environment supports the extension and definition of design-time behavior by classes such as designers that provide design-time support for components. Support for extensible and customizable design mode behavior is an integrated part of the .NET Framework. Tools such as Visual Studio .NET also provide a range of design-time services that designers can use.
This is the webpage if you like to continue reading and view samples from Microsoft
Enhancing Design-Time Support
Everything seems complicated when you just start learning it, heres a working code sample for a UserControl that has a PictureBox and a Label on it. Both controls can be edited during design time, ie. resizing and repositioning, and expose all their events and properties if you click on them.
You will need to add a reference to System.Design, which can only be referenced if you are not targeting ".Net Client Profile." You can change you target profile in Proprieties/Application/TargetFramework.
Add a usercontrol to your project and add a class to handle it's designer. Double click the usercontrol and then add a label and picture box from the toolbar.
Next open that class you create to be it's designer. Add this...
using System.Windows.Forms;
using System.Windows.Forms.Design;
public override void Initialize(IComponent component)
{
base.Initialize(component);
if (this.Control is MyUserControl) // replace this with your usercontrol type
{
// cast this.Control to you type of usercontrol to get at it's
// controls easier
var i = this.Control as MyUserControl; // replace ***
this.EnableDesignMode(i.label1, "unique_name1");
this.EnableDesignMode(i.pictureBox1, "unique_name2");
}
}

Share a (container)control from a (custom)control?

Soo... I am making a control like the Windows Update "panels".
Everything's fine up to the "container" part.
What I want to do is to allow the designer to place controls in a Panel which is inside my control.
(The panel's variable is held in my control's class and inside the control itself.)
How do I bypass this?
As a reference, you might want to try out this AeroWizard Control, which does this pretty well.
(Yes, I have looked at it and didn't find a clue but custom designers!)
As a side note, I'd rather not make a complicated designer class...
If you don't want to create a custom designer class, you should implement your control as a templated custom control, preferably inheriting from CompositeControl.
There doesn't seem to be a way to do the same in Windows Forms without a custom designer class. However, there's a nice, short, working example of such a designer here.

How to hide the inner controls of a UserControl in the Designer?

I have a UserControl that contains a DropDownList and an ObjectDataSource. That control is used in the markup of my MasterPage.
In the Designer of a ContentPage that uses that MasterPage I can see the DropDownList and the ObjectDataSource. See for yourself.
I know that other controls (like ComponentArt:Grid) only show themself as outer container and hide the inner controls.
I guess that is somehow achievable with attributes. Which ones do I have to set?
I'm guessing that the control you refer to, ComponentArt:Grid, have an associated ControlDesigner which can do about anything, including designtime editable areas and custom action menus (the menu associated with the arrow in the upper right corner).
However, Visual Studio does not [last time I tried] execute the control designer for UserControls, so you can not easily control this. There's a lot of magic happening in the background in the UserControlDesigner including parsing the html code. However, I've never seen actual compilation of the codebehind file, where the ControlDesigner attribute would be specified.
You will need to rewrite your control as a server control for Visual Studio to check for the attribute, and allowing your custom designtime view.
I'm not very familiar with WebForms but the BrowsableAttribute might be what you are looking for. Also look at the DesignTimeVisibleAttribute.
The System.ComponentModel namespace has a number of other attributes that may do what you need.
Visual studio doesn't support this. The moment you specify the word "user control", the thing goes beserk and renders everything you put on it.
Fortunately you can influence how server controls are rendered. In other words, you can cheat the Visual Studio designer by making use of that. The code you need can be found here: http://www.codeproject.com/Tips/773145/Hiding-contents-in-ASP-Net-user-control-designer

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