Barcode Scanner - Textbox - VB.NET

M

miss_kait

I would like to emulate the afterupdate event in vb.net after scanning
a barcode.

I have multiple barcodes to scan and after each scan I would like focus
to move to the next text box.

I have mainly stuck with the Key press/down/up events. The wedge
scanner is programmed for a 'return' keystroke after a scan. Only the
first char of the barcode is printing in the text box and then the
focus moves to the next text box.
I appreciate any suggestions! Thanks!
 
S

Shane

It sounds like you're using the "ChangedText" event in your program,
which fires after every character is entered.

Assuming that your wedge is a keyboard wedge, you should be able to
check the ProcessCmdKey on the form. You could try a line like
If keyData = Keys.Enter Then SendKeys.Send("{Tab}") : Return True

Now, that being said, I would create a user control based on the text
box that handles the Enter Key as a tab. It's really easy and with just
a few lines of code. The down side is that you have another dll that
you must distribute with your application.

I also like an event that fires if the value of the textbox changes,
instead of firing on every character. I'll throw this code in as well.

I've also included the optional bitmap entry, if you want to use your
own icon instead of the default icon for your control in the IDE,
otherwise; just delete the line with "ToolboxBitmap"

1) Create a user control called anything you want
2) Switch to the code screen in the IDE
3) Change all of the code above the system generated to

Imports System.ComponentModel
Imports System.Text
<ToolboxBitmap(GetType(YourBitMapName))> _
Public Class YourTextBoxName
Inherits TextBox
Private m_EnterValue As String
Public Event ValueChanged(ByVal sender As Object, ByVal e As
System.EventArgs)

.. . .

4) Add code under the system generated code

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Enter Then SendKeys.Send("{Tab}"): Return True
End Sub

' Bonus code to see if the value changed
Private Sub YourControlName_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Enter
m_EnterValue = Me.Text
Exit Sub

Private Sub YourControlName_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Leave
If m_EnterValue <> Me.Text Then RaiseEvent ValueChanged(sender, e)
Exit Sub

5) Compile the program
6) Add a control under the IDE, Browse to the "bin" directory
containing the dll.
7) Add your new control to your form like any other form.

I've not tested this code, so I may have left something out. I just
pulled a subset of one of my user controls for this reply. Hope it
helps.

More information on creating user controls may be found in the book:
Mastering Visual Basic .NET by Evangelos Petroutsos. The book is pretty
informative, but my binding fell apart after six months! :)
 
C

Chris, Master of All Things Insignificant

Shane said:
Now, that being said, I would create a user control based on the text
box that handles the Enter Key as a tab. It's really easy and with just
a few lines of code. The down side is that you have another dll that
you must distribute with your application.

Why would you have to have another dll? Why not just include it in the
current project, or am I missing something obvious?

Chris
 
K

Ken Tucker [MVP]

Hi,


If you set the forms keypreview property to true this will tab to
the next control every time return is "pressed".

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

If e.KeyCode = Keys.Enter Then

Me.SelectNextControl(Me.ActiveControl, True, True, True, True)

End If

End Sub



Ken

-----------------
I would like to emulate the afterupdate event in vb.net after scanning
a barcode.

I have multiple barcodes to scan and after each scan I would like focus
to move to the next text box.

I have mainly stuck with the Key press/down/up events. The wedge
scanner is programmed for a 'return' keystroke after a scan. Only the
first char of the barcode is printing in the text box and then the
focus moves to the next text box.
I appreciate any suggestions! Thanks!
 
M

miss_kait

Thank you so much! This line of code:
If keyData = Keys.Enter Then SendKeys.Send("{Tab}") : Return True
is exactly what I was looking for.
Our IT team is in the early stages of .NET conversion and so keeping it
simple right now is the key.
Thanks again!
 

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