focus policy

T

Terry von Gease

Is there any way to set, or at least fake, Excel, or windows in general, to
mimic the Motif-like 'focus follows mouse' focus policy?

Assume a sheet and a modeless form displayed. When the mouse cursor moves
onto the form, the form gets the focus, and vice versa, when the mouse
cursor moves from the form onto the sheet, the sheet gets the focus. No
clicking, just moving.

Something on the effective order of:

Sub UserForm_Enter()
Me.someControl.SetFocus or whatever
End Sub
.. . .

Sub Worksheet_Enter()
SetFocus or Activate or whatever
End Sub

While modeless forms are certainly a boon, without being able to do this
they can tend to cause more confusion than they're worth. One never knows
just where one is typing without making sure that the place you assume you
are is in fact the place with the focus.

--
Terry

"I said I never had much use for one,
I never said I didn't know how to use one."
M. Quigley
 
H

Harald Staff

Hi Terry

The event you want, or rather closest to it, is called MouseMove. You can code most your
controls and containers like this:

Private Sub TextBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As
Single, ByVal Y As Single)
TextBox1.SetFocus
End Sub

When it comes to the form itself it's more awkward, and the sheet has no mousemove thing
at all. Adding to the problems that there's no MouseExit event on anything, that the form
or sheet to my knowledge won't activate/deactivate itself by code and that they don't even
know when it happens when done manually. Anyway, I think you'd be 70% there with mousemove
on all form controls.
 
T

Terry von Gease

Thanks, but that's not quite what I had in mind. More like...

Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
Me.Show 0
End Sub

This deals satisfactorily, if incredibly clumsily, with the mouse entering
the form. If I place two modeless forms on a sheet, each with the above in
their code, then moving the mouse from one to the other activates the one
under the mouse cursor and thus deactivates the other. This works but
somewhat less than elegantly since you can move the mouse rapidly and
confound it.

But that's only half the battle. The hard part would seem to be knowing when
either the mouse enters the sheet or leaves the form. Since the cursor
changes at this event, there must be something somewhere that knows that the
sheet is being entered. How does one get in front of that event?

Some magic in the API? What?

--
Terry

"I said I never had much use for one,
I never said I didn't know how to use one."
M. Quigley
 
H

Harald Staff

Ok, 50% then <g>. I'm sure it can be found, either a cursor position or cursor change
event. But I haven't managed to create code that deactivates the form(s) and refocuses the
sheet, so simply detecting won't do either. I'll play more around with it when time
allows, let's hope someone has a somution in the meantime.
 

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