-
Oct 22nd, 2020, 11:24 AM
#1
Thread Starter
New Member
How to keep focus on textbox when opening a browser or another app from an action
Hi.
We have an app (in VB .net) where a user uses Dragon to enter text (voice to text) in a specific textbox. The problem is that we have a button that has the action to open a browser window and the user loses focus from the box.
Is there a way to keep the focus on said textbox when opening the other app? So that the user continue using dictation without having to go back with a mouse.
Thanks en advance!
-
Oct 22nd, 2020, 11:29 AM
#2
Re: How to keep focus on textbox when opening a browser or another app from an action
This is likely two-fold:
- The Focus in your application switches to the button
- Your application is no longer the active window
You will likely need to use the SetForegroundWindow API (documentation) to make your application active after the browser opens.
You can switch focus from the button to your textbox by calling the Select method (documentation).
-
Oct 22nd, 2020, 11:36 AM
#3
Thread Starter
New Member
Re: How to keep focus on textbox when opening a browser or another app from an action
Thank you very much for the infor dday9! I'll be checking the documentation tonight
-
Oct 22nd, 2020, 11:45 AM
#4
Re: How to keep focus on textbox when opening a browser or another app from an action
I started thinking about it and it seems as if you want your form to be the topmost form anyways. If that's the case, I would do one of two things depending on what you're trying to achieve:
- Set the Form's TopMost property to True (documentation)
- Setup a checkbox that the user can check/uncheck to toggle the TopMost property and set the checked state to true by default
-
Oct 22nd, 2020, 12:08 PM
#5
Thread Starter
New Member
Re: How to keep focus on textbox when opening a browser or another app from an action
"Setup a checkbox that the user can check/uncheck to toggle the TopMost property and set the checked state to true by default"
This is what i was trying to do with another method but it was not working. I'll try with setting the topmost property of the form to true first.
Thanks again!
-
Oct 22nd, 2020, 03:45 PM
#6
Re: How to keep focus on textbox when opening a browser or another app from an action
Actually, I just tested it on my end. Setting the TopMost property alone won't work because even though the application is at the top of the z-order, it still isn't the active window.
You'll still need to use the SetForegroundWindow API.
-
Oct 22nd, 2020, 07:12 PM
#7
Re: How to keep focus on textbox when opening a browser or another app from an action
Originally Posted by dday9
This is likely two-fold:
- The Focus in your application switches to the button
- Your application is no longer the active window
You will likely need to use the SetForegroundWindow API ( documentation) to make your application active after the browser opens.
You can switch focus from the button to your textbox by calling the Select method ( documentation).
It may or may not be what you want but it is possible to create a custom Button control that doesn't take focus when you click it. That would solve that part of the problem at least. If you're interested, follow the CodeBank link in my signature below and check out my On-Screen Keyboard thread.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|