can you create one "MouseEnter" event handler for multiple controls on a form?

J

JohnR

I have a form with a number of text boxes, comboboxes etc. What I would
like to do is create an event handler for the "mouseenter" event for each of
the controls whereby I display information about the control they just
entered (sort of like an extended tooltip). Now, I can certainly create a
separate mouseenter event for each control (too much work, and not very
clever), but what I would like to do is somehow create one event that would
trigger on the "mouseenter" of any control on the form (much less work, and
very clever). Hopefully, this event will pass a "sender" parameter where,
in the event handler, I can determine which control just got entered, and
display the appropriate message for the user. I have scanned all controls
on a form to do other things (formatting, etc), but if I pick up an
arbitrary control from the 'controls' collection how would I go about
defining a mouseenter event for it? If I can do that, I can loop thru all
the controls and programmatically create mouseenter events for them.

I have a feeling that this can somehow be done, but I'm at a loss as how to
go about it. Can anybody give me some ideas as to how this might be done.

Thanks.
 
H

Herfried K. Wagner [MVP]

JohnR said:
I have a form with a number of text boxes, comboboxes etc. What I would
like to do is create an event handler for the "mouseenter" event for each
of the controls whereby I display information about the control they just
entered (sort of like an extended tooltip). Now, I can certainly create a
separate mouseenter event for each control (too much work, and not very
clever), but what I would like to do is somehow create one event that would
trigger on the "mouseenter" of any control on the form (much less work, and
very clever). Hopefully, this event will pass a "sender" parameter where,
in the event handler, I can determine which control just got entered, and
display the appropriate message for the user.

You can either add the handlers at runtime in the 'Handles' part of a
'MouseEnter' event handler ('... Handles Button1.MouseEnter,
Button2.MouseEnter, ...', or you can bind the handler to controls' events
using 'AddHandler' at runtime (see documentation).
 

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