Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have created an application with vs 2012(winform application) that scan a code barre of product and automatically detect a name of product from a database , i need how i can use a code bar scanner with my application in order to detect automatically the value of the code without press a button ?
Posted
Updated 28-Jun-15 10:12am
v2

Most scanners are configured to act as a keyboard, so as long as your application is "sitting" with the focus in a text box or similar the barcode data should be entered automatically.
If that isn't what you need, it is normally possible to change the way they work to (say) provide a start and end code your application can recognise - buy that needs to be worked out with the equipment manufacturer.

Once you have the barcode, it's pretty obvious how you use that to look up the related product in your DB and work with it.
 
Share this answer
 
It's really simple - please refer to one of my previous answers to the same kind of question: How to read a barcode using a barcode scanner[^]

In addition to the linked answer: Most barcode scanners automatically append a return character to the scanned barcode by default, otherwise it can be configured that way (or to append a different or no character).

Edit after comment:
If you have your barcode scanner configured to append a return character then you can use this kind of code to process a scanned barcode:
C#
public Form1()
{
    InitializeComponent();

    BarcodeTextBox.KeyDown += BarcodeTextBoxKeyDown;
}

private void BarcodeTextBoxKeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter) // wait for the return character
    {
        string barcode = BarcodeTextBox.Text;
        BarcodeTextBox.Text = "";
        e.Handled = true;

        // todo: do something with barcode
    }
}
 
Share this answer
 
v2
Comments
Mohammed-cd7 28-Jun-15 20:56pm    
I Am using textchanged event in order to when the bar code scan the code ,automatically select name of product of the code in textbox but i have a problem because when i scan, the programme use only the first character in textbox this is my problem
Sascha Lefèvre 28-Jun-15 21:21pm    
I updated my answer above, please take a look.
Mohammed-cd7 29-Jun-15 13:32pm    
thank you for the solution but what is the role of e.Handled = true ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900