Reputation: 143
I´m trying to set textbox visible = false to avoid user from write on it manually but I still need it to write on it by using a bar code scanner, so I need it to get focused before use the scanner, what would be the better way to do it?
Upvotes: 2
Views: 2524
Reputation: 567
just simply set textbox property size to (0,0) with textbox visible = true
Upvotes: 2
Reputation: 429
Your best option would be to simply validate that what's entered into the textbox is indeed a bar code. What happens when the scanner breaks down and the user still needs to enter a bar code? Limit it to numbers only.
If that's not an option and you find the scanner doesn't work with hidden or disabled textboxes, then set TabStop = false
and Multiline = true
, and try setting the text box size to 0x0. Or at least really tiny and make it the same colour as the background. In that case you'd want a label or something to then display the bar code or product info so the user knows the scanning worked.
Another possibility may be to set KeyPreview = true
on your form. Then you can handle anything that looks like a bar code in the form's KeyPress
event, no matter which control is focused. If numbers start coming in, capture them, and if it turns out not to be a bar code, just forward them to the focused control.
Upvotes: 2
Reputation: 29
If the purpose of hiding textbox is to not-allow user from editing it, then you may set the ReadOnly property of texbox to true, then call the .Focus() method before scanning the barcode. In my experience, after having installed the barcode reader driver, softwares from accompanying CD, all you have to do is scan the barcode and it will populate with the barcode-value in human readable format, on any control in an application that can take user-input. I suggest to use Readonly property of textbox instead of setting visible = false.
Upvotes: 0
Reputation: 2926
From the question, you want to achieve two things.
Solution
Set the textbox visibility property to false
before Scanning so that it does appear on the screen whatsoever.
Have an event handler after finishing scanning or at the end of your scanning method/function, change the Property
of the textbox called Disabled
to true
.
Hope this helps.
Upvotes: 0