By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,205 Members | 933 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,205 IT Pros & Developers. It's quick & easy.

temporarily disable focus changing

P: n/a
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
Nov 25 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

--
Cheers,
Gary
http://www.garyshort.org/

Nov 25 '06 #2

P: n/a

<ga**@garyshort.orgwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
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
Nov 26 '06 #3

P: n/a
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?

--
Cheers,
Gary
http://www.garyshort.org/
Jon Slaughter wrote:
<ga**@garyshort.orgwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
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
Nov 26 '06 #4

P: n/a

<ga**@garyshort.orgwrote in message
news:11**********************@14g2000cws.googlegro ups.com...
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
Nov 26 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.