Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

read barcode with barcode scanner c# winform serial port number

public class ScannerTextBox : TextBox
{
    public bool BarcodeOnly { get; set; }

    Timer timer;

    private void InitializeComponent()
    {
        this.SuspendLayout();

        this.ResumeLayout(false);
    }

    void timer_Tick(object sender, EventArgs e)
    {
        if (BarcodeOnly == true)
        {
            Text = "";
        }

        timer.Enabled = false;
    }

    protected override void OnKeyPress(KeyPressEventArgs e)
    {
        base.OnKeyPress(e);

        if (BarcodeOnly == true)
        {
            if (timer == null)
            {
                timer = new Timer();
                timer.Interval = 200;
                timer.Tick += new EventHandler(timer_Tick);
                timer.Enabled = false;
            }
            timer.Enabled = true;
        }

        if (e.KeyChar == '
')
        {
            if (BarcodeOnly == true && timer != null)
            {
                timer.Enabled = false;
            }
        }
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #read #barcode #barcode #scanner #winform #serial #port #number
ADD COMMENT
Topic
Name
4+7 =