ComponentDesigner

  • Thread starter Thread starter Mark Olbert
  • Start date Start date
M

Mark Olbert

I've written a component whose design surface I only want to accept SqlDataAdapters and DataSets. In
other words, if the user attempts to drop any other component on the surface I want to block it (or
remove it).

I've tried a number of different approaches to implementing this kind of behavior, but so far
they've all failed (kudos again to Microsoft for horribly inadequate documentation!) I thought the
way to try to do something like this would be to implement a ComponentDesigner for my component, and
then set methods to react to IComponentChangeService events.

Unfortunately, even though I put the Design() attribute on the component class, and even though the
ComponentDesigner I wrote derives from ComponentDesigner... nothing in ComponentDesigner ever gets
called when I open up the design surface in a component derived from my component.

I'm at a loss trying to understand why none of the methods in my ComponentDesigner class, including
Initialize(), ever get called. Or does the ComponentDesigner do something other than handle the
design-time surface of the component?

- Mark
 
Hi Mark,

There are actually two designers on Component class, one is the
ComponentDesigner which is used in the Form component tray, it provides a
way to customize the design-time behavior of the component when it is on
the form,
Another designer is the an ComponentDocumentDesigner which is an
RootDesigner for the component , it is used to support design of the
component itself.
From your description, I think you are trying to customize the behavior of
the ComponentDocumentDesigner. You may use a customized Root designer for
your component in this way:

[Designer(typeof(MyComponentDocumentDesigner),typeof(IRootDesigner))]
class MyComponentContainerBase : Component {}

//VS.NET will use the Designer on parent class
class MyComponentContainer : MyComponentContainerBase
{}

class MyComponentDocumentDesigner : ComponentDocumentDesigner
{
public override void Initialize(IComponent component)
{
MessageBox.Show("Hello");
base.Initialize (component);
}
}

If the customized root designer is created successfully, you will see a
MessageBox when you switch to the designer view of MyComponentContainer.

There is an article (with sample) describes how to write a simple shape
designer for your component, you may find it in
http://windowsforms.net/articles/shapedesigner.aspx
I hope it will be helpful to you.
Note the SubType of file MyShape.cs in "ShapeLibraryTestProject.csproj" is
marked as "code", you might need change it to "Component" to see its
designer view.

Does my answer resolve your problem?
Please feel free to reply this thread if you have further questions on it.

Thanks!



Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Back
Top