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

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.

Related

Windows Form multiple designer for a control

I made a custom designer for a control. The problem is that the base class has a designer, too. Since it's marked as internal, I can't inherit from it. Is there a way to force the designer to use multiple designers for a control?

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");
}
}

How to add design-time support for Enabled property in Winforms

I've created a Winforms UserControl (Visual Studio 2008, 3.5 Framework SP1). I've been able to create some of my own public properties that Visual Studio is able to properly handle (i.e. the form designer properly reacts to changing property values).
I would like to set the Enabled property a CheckBox control according to the Enabled property of the UserControl. This would be under UserControl1.cs:
`chkMyCheckbox.Enabled = Enabled`
I have tried putting this both under the EnabledChanged event of the UserControl and overriding the OnEnabledChanged method, but neither seems to catch. This is not a toolbox caching issue (b/c I can see other code changes taking effect).
Thanks in advance,
-Alan.
The way a control is rendered at Design-Time is up to the designers of that control. The core Win32 controls do not render themselves as Disabled when in the Designer.

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.

Customizing the behavior of ControlDesigners for Controls derived from native .NET controls

My question is related to this question:
Baseline snaplines in custom Winforms controls
However, in my case, I have created a new control that derives from TextBox rather than containing a TextBox. I would like to have a custom ControlDesigner, but I would like to modify the behavior of the TextBox's designer rather than having to write a complete designer myself. In particular, I'd like to be able to return the TextBox's SnapLines while providing some custom verbs. Is there a good way to do this?
EDIT: To clarify, this is for Windows Forms in .NET 2.0.
In the end, the solution I settled on was to create a dummy control in the designer, sync the relevant properties with the real control, get the designer for the dummy control, and then return the snaplines from the dummy control's designer. It's a terrible hack, but it seems to be the only way without using reflection to "extend" a designer.
What about having your ControlDesigner derive from the one that TextBox is using? Did you try that and find a problem?

Categories

Resources