How to handle mouse events (Enter & Leave) in an mdi?


I have an form with a panel holding a treeview menu, a commandline and a list with the last 20 commands used, on the left hand side.  I use a splitter to resize the panel to allow the user to resize it at will. But i also need to make an autohide function. I adde a Tagpin (button) that resizes the whole panel to a minimum width. Now the panel has to slide open or close when the mouse enters or leaves it.
On a normal form I use the forms mouse enter and leave events to do so and it works like a charm. Now the same form has to be used as an MDI. So setting the mdicontainer = true should be the only thing I have to do However, the mouse events don't seem to happen anymore and the autohide no longer works.
How can I trigger the mouse events To allow my form and panel to work regardless of being an mdi or not?

We need this form ASAP as it is a main part of the framework we are building and without it all other projects based on the framework are on hold.


Alain Boone
Who is Participating?
Fenris_LokissonConnect With a Mentor Commented:
The mdiform has an mdiclient that holds all the childs. It can be found in the forms controlcollection.

By creating an instance of an mdiclient with events and adding an eventhandler handling the mouse enter and mouseleave and linking it to the sub you want to run, you can catch the events.


On the MDIform, create an mdiclient

private withevents fmdiC as mdiclient

In the form load, link it to the mdiclient if there is one

dim i as integer
for i = 0 to mdiform.controls.count-1
  if mdiform.controls(i).gettype.tostring = "mdiclient" then
     fmdiC = mdiform.controls(i) 'if option strict, don't forget to ctype to mdiclient: ctype(mdiform.controls(i),mdiclient)
     addhandler fmdic.mouseenter addressof ... 'the sub or function that has to handle the event. You could for example link it to
                                                                    'the forms mouseenter event by setting addressof mdiform_mouseenter
     exit for
   end if
next i
PaybitAuthor Commented:
I just had to change the gettype.tostring = "mdiclient" beacause the string returned = "System.Windows.forms.MdiClient" and it has to be exactly the same, including the upper and lower casing.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.