how to force a text box to always be in focus.

A

AussieRules

Hi,

I have an application that has a single text box, but many many buttons, and
a few other controls (grid etc).

The problem is that the application has a barcode scanner that acts like a
keyboard. What I need to have is that the text box always has the focus, so
at anytime the barcode scanner is used, the value is in the text box.

If I push a button or slide the grid etc, the focus moves from the text box
to the other control, which means when the bar code scanner scans, the value
is not entered into the text box.

Is there a way to have it so that the txt box always has the focus, yet the
other controls still work ?
 
E

eBob.com

AussieRules said:
Hi,

I have an application that has a single text box, but many many buttons,
and a few other controls (grid etc).

The problem is that the application has a barcode scanner that acts like a
keyboard. What I need to have is that the text box always has the focus,
so at anytime the barcode scanner is used, the value is in the text box.

If I push a button or slide the grid etc, the focus moves from the text
box to the other control, which means when the bar code scanner scans, the
value is not entered into the text box.

Is there a way to have it so that the txt box always has the focus, yet
the other controls still work ?
I don't understand. TextBox.Text = "whatever" works whether TextBox has the
focus or not. And the assigned value is displayed whether TextBox has the
focus or not.

Bob
 
O

Onur Güzel

Hi,

I have an application that has a single text box, but many many buttons, and
a few other controls (grid etc).

The problem is that the application has a barcode scanner that acts like a
keyboard. What I need to have is that the text box always has the focus, so
at anytime the barcode scanner is used, the value is in the text box.

If I push a button or slide the grid etc, the focus moves from the text box
to the other control, which means when the bar code scanner scans, the value
is not entered into the text box.

Is there a way to have it so that the txt box always has the focus, yet the
other controls still work ?

Do not consider that advice as a brute-force tip, but can't you
consider this:

' Try to handle LostFocus event and re-focus before losing focus
Private Sub TextBox1_LostFocus(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TextBox1.LostFocus
TextBox1.Focus()
End Sub

It may -not- be useful if your form design deals with another control
pattern based on the user interaction principles.

HTH,

Onur Güzel
 
C

Cor Ligthert[MVP]

Hi Onur,

That was the one I forgot,

You are right, but what is brute in the given question?

Cor
 
F

Fred

AussieRules said:
Hi,

I have an application that has a single text box, but many many
buttons, and a few other controls (grid etc).

The problem is that the application has a barcode scanner that acts
like a keyboard. What I need to have is that the text box always has
the focus, so at anytime the barcode scanner is used, the value is in
the text box.

If I push a button or slide the grid etc, the focus moves from the
text box to the other control, which means when the bar code scanner
scans, the value is not entered into the text box.

Is there a way to have it so that the txt box always has the focus,
yet the other controls still work ?

Perhaps you can use Form.KeyPreview property and Form.KeyDown event ?
 
O

Onur Güzel

Hi Onur,

That was the one I forgot,

You are right, but what is brute in the given question?

Cor

Hi,
I just meant that this technique may not be desirable by clients
(users of application) and whether the OP's form design is suitable
for this. Forcing users to accept a mandatory application behaviour
may annoy them. But if it's a private application (which is not
deployed to any clients and will be used in his own company) or that
is meant to be used by author, it seems useful.

Onur Güzel
 

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