temporarily disable focus changing

J

Jon Slaughter

Is there any method to temporarily disable focus changing?(I assume only
method is tab or mouse?) This problem has been tieing me up for a while and
nothing seems to work. The only thing that I *know* will work is to disable
all tab stops on all controls. This brute force method doesn't seem like a
good idea though.

What I wanted to do was take control the control enter/leave and mouse
enter/leave and "switch back" the focus when it is changed. I would do this
by keeping track of the last control that had focus before it was changed.
The problem here though is that because of the way the events are fired I
cannot do it properly it seems the entered routine is called before the
leave of the last control and hence I would overwrite the state. I thought
about keeping a "2-deep" state and I would ignore the first because it would
always be pointing to the current control. The problem here is that this
seems like a hack and I'm not sure it will work in all cases ;/


Any ideas?

Essentially what I want is for any control with the mouse entered to take
control of the focus and not release it until that control does not have the
mouse on it. When the mouse leaves that control then the focus will go back
to the original control before the new control was entered. The problem I
have with my code now is that the user can hit the tab button and change
focus while the mouse is over a control which screws everything up. I also
need this to work with pre-existing net controls so I have to override the
events to handle it instead of creating a custom control.

Thanks,
Jon
 
G

gary

Hello Jon,

This seems fairly straight forward, all you need to is to trap the
"Leave" event. Do what ever test you need to check if the user can
leave the control and if they can't then cancel the event.
 
J

Jon Slaughter

Hello Jon,

This seems fairly straight forward, all you need to is to trap the
"Leave" event. Do what ever test you need to check if the user can
leave the control and if they can't then cancel the event.

The problem is that the focus is internally handled. You cannot disable it
or modify it except through overriding the wndproc.

Now you might be able to "reset" the focus back to the current control but
this depends on the order of the events recieved. I'll try it and see but
I'm not sure if it will work as I've already tried something very similar.

Thanks,
Jon
 
G

gary

Ah I see what you are saying, it's because you can't rely on the order
in which events will be received. Do you trap many events from the
control?
 
J

Jon Slaughter

Ah I see what you are saying, it's because you can't rely on the order
in which events will be received. Do you trap many events from the
control?

Yeah, The order is supposed to be specified. MSDN says enter, ..., then
finally leave. I'm not sure if this is quite true though as when my code
works for the mouse switching sometimes in very rare circumstances it looses
the last focused control in some manner(the code is very simple).

So only thing I can think of is that the the events for the two controls(the
one that was left and the other that was entered) are fired in an
overlapping way that screwed up everything.

At this point I'm just writing the code to handle this particular aspect.

The main problem is to somehow disable the ability of a control to have
focus. I have no idea how to do this ;/ There doesn't seem to be able
property to disable focus except tabstop. But here I don't know if there are
other methods of changing focus or just this one ;/ If so then I could just
creating a hash table that holds the tabstop state for all the controls and
then disable tabstop for all the controls any time I'm inside a control.
This way the user cannot tab out of it.

I'm not sure if this will work well though and seems like an overkill just
to disable focus changing.

Thanks,
Jon
 

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