Discussion:
Deriving from ParentControlDesigner in .NET 2.0
(too old to reply)
Richard
2007-12-11 20:00:01 UTC
Permalink
Hello,

I am trying to write a class that derives from ParentControlDesigner so that
I can pre and post filter properties. But I am unable to figure out what
DesignerAttribute I need to put on my control in order for it to work
properly. Here is a summary example:

public class MyDesigner: ParentControlDesigner
{
}

Case 1: works, but I do not get any behaviors from ParentControlDesigner
(D&D, selection services, etc.)
[Designer(typeof(MyDesigner), typeof(IRootDesigner))]
public class MyControl: UserControl
{
};

Case 2: works wonders, except that MyDesigner is not even created!
[DesignerAttribute(typeof(MyDesigner), typeof(ParentControlDesigner))]
public class MyControl: UserControl
{
};

Case 3: Crashes at runtime, PerformLoad says that it could not find a designer
[DesignerAttribute(typeof(ParentControlDesigner), typeof(IRootDesigner))]
public class MyControl: UserControl
{
};

thank you,

Richard
Linda Liu[MSFT]
2007-12-12 06:42:10 UTC
Permalink
Hi Richard,

You should add the DesigerAttribute as follows:

[Designer(typeof(MyDesigner), typeof(IDesigner))]
public class MyControl: UserControl
{
}

Note that the DesigerBaseType should be typeof(IDesigner).
typeof(IRootDesigner) is used as the DesigerBaseType for Forms.

- or -
// you needn't specify the DesignerBaseType at all
[Designer(typeof(MyDesigner))]
public class MyControl: UserControl
{
}

In addition, only when you put a MyControl onto a form at design time, the
MyDesigner works. The MyDesigner doesn't work in the case that you open the
MyControl in the designer by double-clicking it in the Solution Explorer.

Hope it helps.
If you have any questions, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Richard
2007-12-12 14:26:02 UTC
Permalink
Hello Linda,

Good to hear from you!

First, I am not under VS.NET, I am writing my own runtime host which is
based on the "DesignerHosting" sample. As I have mentionned, all is well
until I want to have a designer on the root component.

You mention that it won't work if it is double-clicked, how does this relate
to the DesignerHosting sample? Is this why I do not seem able to have a
proper Root designer on my Root Control? How can I pre/post filter
properties on the Root Control?

The pre/post filtering does work when I drop a MyControl onto the MyControl
being designed... Although, there are no grabbing handles and the like...

Thanks,

Richard
Post by Linda Liu[MSFT]
Hi Richard,
[Designer(typeof(MyDesigner), typeof(IDesigner))]
public class MyControl: UserControl
{
}
Note that the DesigerBaseType should be typeof(IDesigner).
typeof(IRootDesigner) is used as the DesigerBaseType for Forms.
- or -
// you needn't specify the DesignerBaseType at all
[Designer(typeof(MyDesigner))]
public class MyControl: UserControl
{
}
In addition, only when you put a MyControl onto a form at design time, the
MyDesigner works. The MyDesigner doesn't work in the case that you open the
MyControl in the designer by double-clicking it in the Solution Explorer.
Hope it helps.
If you have any questions, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Linda Liu[MSFT]
2007-12-14 01:49:34 UTC
Permalink
Hi Richard,

I thought you were using a custom designer for UserControl in VS IDE.

Well, since what you want is to implement a designer for a root component
within your own runtime host, you must implement the IRootDesigner
interface for your custom designer, i.e. MyDesigner.

The easiest way to do this is to derive from DocumentDesigner instead of
ParentControlDesigner.

The Designer attribute that takes the second parameter of IRootDesigner is
correct. When you are the root of a document, the design surface looks for
a designer of type IRootDesigner.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
Richard
2007-12-14 16:14:00 UTC
Permalink
Hello Linda,

As soon as I implement IRootDesigner and derive from ParantControlDesigner
or DocumentDesigner, I am unable to edit MyControl - like I have mentionned
in my original post (case 1);

public class MyDesigner : DocumentDesigner, IRootDesigner

It does create MyDesigner, calls the IRootViewer's GetView, where I create a
MyControl... but then, I am not able to drag and drop toolboxItem onto the
surface...

Please advise,

Richard

Case 1: works, but I do not get any behaviors from ParentControlDesigner
(D&D, selection services, etc.)
[Designer(typeof(MyDesigner), typeof(IRootDesigner))]
public class MyControl: UserControl
{
};
Post by Linda Liu[MSFT]
Hi Richard,
I thought you were using a custom designer for UserControl in VS IDE.
Well, since what you want is to implement a designer for a root component
within your own runtime host, you must implement the IRootDesigner
interface for your custom designer, i.e. MyDesigner.
The easiest way to do this is to derive from DocumentDesigner instead of
ParentControlDesigner.
The Designer attribute that takes the second parameter of IRootDesigner is
correct. When you are the root of a document, the design surface looks for
a designer of type IRootDesigner.
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Linda Liu[MSFT]
2007-12-18 06:54:16 UTC
Permalink
Hi Richard,

Sorry for my delayed reply!

You needn't implement the IRootDesigner interface for the MyDesigner class
because the DocumentDesigner class has implemented the IRootDesigner
interface.

To custom draw the root design mode view, you can override the
OnPaintAdornments method in the MyDesigner class.

The following is a sample.

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;

public class RootViewSampleComponent : RootDesignedComponent
{
public RootViewSampleComponent()
{
}
}
[Designer(typeof(SampleRootDesigner), typeof(IRootDesigner))]
public class RootDesignedComponent : Control
{
public RootDesignedComponent()
{
}
}

public class SampleRootDesigner : DocumentDesigner
{
protected override void OnPaintAdornments(PaintEventArgs pe)
{
base.OnPaintAdornments(pe);
pe.Graphics.FillRectangle(Brushes.Blue,
Control.ClientRectangle);
pe.Graphics.DrawString(Control.Site.Name, Control.Font,
Brushes.Yellow, Control.ClientRectangle);
}
public override void Initialize(IComponent component)
{
base.Initialize(component);
Control.Size = new Size(150, 150);
}
}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Loading...