How to know when a component is draged on a form?

M

Mario Vázquez

Hi all,
I'm trying to build a component which takes advantage of other components.
So, when this new component is draged to the form, I would like to insert
other components on the designer and relate them. But only the first time
the component is inserted! to avoid inserting components each time de form
is loaded in the IDE.
How can I hook the very first time a component is draged on a windows form?

Thanks for attention,
Mario Vazquez
 
C

Carlos J. Quintero [VB MVP]

Hi,

I was also interested in that problem and I found that the ComponentAdded
event does not provide that info. There are several cases:

- A component added from the toolbox
- A paste operation
- An undo operation (that places a control that was deleted)
- ...

Maybe a control designer has other hooks but the ComponentAdded event that
add-ins can use doesn't.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
 
M

Mario Vázquez

Hi Carlos,

Thanks for the tip.
Well, it seems not an easy issue.
I've just found an interface (framework 2.0) that may help.
IComponentInitializer
It has two methods which give a choice to hook the creation of new and
existing components. But i've not investigate if this is true for all the
cases you expose.

Regards,
Mario Vazquez
 
C

Carlos J. Quintero [VB MVP]

Ah, yes, I found that interface sometime ago but I don't know how to use it
from outside a control designer (from an add-in, for example). Let me know
if you get more info.


--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
 
M

Mario Vázquez

Hi Carlos,

I still have'nt work with add-ins and macros, so I cannot properly talk
about it, but I'll explain you how I use this interface through the designer
of a component, and perhaps it helps you.
Anyway, I was testing the points you expose in your previous message, and
this interface does'nt solve them.

// Make the designer implements IComponentInitializer
class MyComponentDesigner:System.ComponentModel.Design.ComponentDesigner,
IComponentInitializer
{
...

// Implement the interface
void
IComponentInitializer.InitializeExistingComponent(System.Collections.IDictionary
defaultValues)
{
base.InitializeExistingComponent(defaultValues);
// hook point
}

void
IComponentInitializer.InitializeNewComponent(System.Collections.IDictionary
defaultValues)
{
base.InitializeNewComponent(defaultValues);
// hook point }
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top