Provider Properties + IExtenderProvider

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there any way to create an extender that provides an event to all controls
that
I return CanExtends==true for? It seems I can provide properties, like
strings, bools, ints, but not events to other controls.

The reason I would like to do this is so I can associate an event with the
control and have the designer automatically add the event handler for me when
the user double clicks the event in the event pane of the designer for the
control.

Is there a way to do this?
Thanks,
Dave
 
You can return true to all cases from CanExtend. You might do this if you
wanted to provide a property for anything based on Component for example.

The IExtenderProvider only enables you to add a property at design time. You
can't add an event.

It's important to note that the property isn't really added to the object.
This is just a design time trick that enables the IDE to make the user think
that the object has properties it doesn't. At runtime those properties do
not exist and must be handled by the property provider itself. More
particularly, the object being extended has no knowledge that the addition
has taken place and so for it to magically gain an event in this manner
would make no sense.

Maybe you should explain in detail what you want to do rather than speculate
on the operation of the extender provider. There may be another way to
answer the question.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
What I would like to do is for controls like menu items, or buttons add (or
others) add an event to them that can be seen and added in the designer by
double clicking on it. I am going to have the provider property link up this
event based on another provider property added to the control.

Is the only way to do this to derive a class from each control I want the
event on and add the event to that derived class (for example menu items?)
The problem is I want all menu items to have it even if they are part of a
Main menu or context menu.

The purpose is to associate the newly created event handler. This allows
the developer to easily create event handlers through the designer and allows
me to internally link up the handler. I understand it is just a designer
effect that is the purpose I am going for to make it easy for developers to
associate a special event handler with any control I choose.

If it can't be done this way, any other possibilities, VS-Addin's, if so any
hints on how to pull that off?

Thanks,
Dave
 
A second question I ran into is, how to determine if I am in design mode in
my component when it first gets initialized. DesignMode does not appear to
be set propertly when I check it in the constructor of my component but it is
set by the time either property or CanExtend gets called. My workaround
currently checks the first time CanExtend is called it adds my event handler.
This seems like a hack.

I tried an alternate method when I derive my component from
ISupportInitialize and try to do work in the BeginInit method so I can hook
up designer events for my component at design time to see if my component was
removed or not. This method is not called until the form itself is recompiled
so I never got the chance to add the event method to know if my component got
removed, which means I leave some items on the form when my component gets
removed. (The example scenario is someone adds the component on the form..
does a bunch of things on it to cause a bunch of internal components to be
generated, then remove the component from the form... I can't rely on
BeginInit as it does not seem to be called the first time the component is
dropped on the form, until it is recompiled.)

Is there a better way to do this? I'm about to try getting a reference to
the DesignerHost and just check to see if it's null.

Ideas?
 
Back
Top