Answers for "read barcode with barcode scanner c# winform serial port number"

C#
0

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 == '\r')
        {
            if (BarcodeOnly == true && timer != null)
            {
                timer.Enabled = false;
            }
        }
    }
}
Posted by: Guest on May-06-2022

C# Answers by Framework

Browse Popular Code Answers by Language