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

  • Thread starter Thread starter AussieRules
  • Start date Start date
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 ?
 
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
 
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
 
Hi Onur,

That was the one I forgot,

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

Cor
 
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 ?
 
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
 
Back
Top