Question about textControl - Navigation vs Edit mode from code

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

Been stuck on this one for a long time now.
(Please do not confuse "Edit Mode" in the question below with AllowEdit)

Once a text control gets focus, is there any way from code to tell what mode
it is in (Navigation or Edit)?

When you tab to a field, you arrive there in "Navigation mode" (all text is
highlighted), however, if you click in the text control, you enter it in
"Edit mode" (flashing cursor). I know that when you press F2 you can toggle
between modes but I need to know which mode I am in...
i.e. Screen.ActiveControl.WhatModeDamnIt

Alternatively, is there anyway to change the mode other than sending an F2
via sendkeys?
i.e.Me.MyControl.SetFocus
Me.MyControl.SetModeToEdit

The problem with sending an F2 key is that, if you don't know what mode you
are in to start with, you may be switching to the wrong mode.

The only thing I've come up with so far is to setfocus quickly over to
another control and then back again so the I know for sure I am in
Navigation mode, Then send an F2 keystroke (which is stupid).

Please help,
Tiffany
 
When you tab into a control, all characters are selected.

Assuming you are in a text box or combo, you could examine
Form.ActiveControl, to see if SelStart is the beginning and SelLength is all
characters, i.e. Len(.Text)

I don't think you wanted to change what happens when you enter a control,
but that is configurable through:
Tools | Options | Keyboard
 
That will probably do the trick. Now the other question is... Is there a
way to change the mode through code without sending an F2 key?

Thanks,
Tiffany
 
F2 just toggles between selecting all the characters in the field, and
placing the curor at the end. You can set SelStart and SelLength to simulate
this.

As you probably know, SendKeys is not a good idea, due to the bug with the
NumLock status and the assumption about what application, window, and
control has focus.
 
Back
Top