.NET Forum / Windows Forms / Design Time / December 2007
Deriving from ParentControlDesigner in .NET 2.0
|
|
Thread rating:  |
Richard - 11 Dec 2007 20:00 GMT 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] - 12 Dec 2007 06:42 GMT 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 - 12 Dec 2007 14:26 GMT 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
> Hi Richard, > [quoted text clipped - 45 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights. Linda Liu[MSFT] - 14 Dec 2007 01:49 GMT 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 - 14 Dec 2007 16:14 GMT 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 { };
> Hi Richard, > [quoted text clipped - 17 lines] > Linda Liu > Microsoft Online Community Support Linda Liu[MSFT] - 18 Dec 2007 06:54 GMT 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
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|