using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Barcodetesting_14_7 { public partial class Form1 : Form { private Dictionary<textbox, textbox=""> TextBoxOrder = new Dictionary<textbox, textbox="">(); private void Form1_Load(object sender, EventArgs e) { } public Form1() { InitializeComponent(); TextBoxOrder.Add(BarcodeInput1, BarcodeInput2); TextBoxOrder.Add(BarcodeInput2, BarcodeInput3); TextBoxOrder.Add(BarcodeInput3, BarcodeInput1); BarcodeInput1.Tag = 1; BarcodeInput2.Tag = 2; BarcodeInput3.Tag = 3; BarcodeInput1.KeyDown += BarcodeInputKeyDown; BarcodeInput2.KeyDown += BarcodeInputKeyDown; BarcodeInput3.KeyDown += BarcodeInputKeyDown; BarcodeInput1.Leave += BarcodeInputLeave; BarcodeInput2.Leave += BarcodeInputLeave; BarcodeInput3.Leave += BarcodeInputLeave; } private void BarcodeInputKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && ActiveControl.GetType() == typeof(TextBox)) { TextBox nextTextBox; if (TextBoxOrder.TryGetValue((TextBox)ActiveControl, out nextTextBox)) { e.Handled = true; e.SuppressKeyPress = true; nextTextBox.Focus(); } } } private void BarcodeInputLeave(object sender, EventArgs e) { if (sender.GetType() == typeof(TextBox)) { TextBox textBox = (TextBox)sender; if (textBox.Tag.GetType() == typeof(int)) { BarcodeScanned(textBox.Text, (int)textBox.Tag); } } } private void BarcodeScanned(string barcode, int order) { DemoLabel.Text = order.ToString() + ": " + barcode; } } }
DemoLabel.Text = order.ToString() + ": " + ((barcode.Length > 10) ? barcode.Substring(barcode.Length - 10, 10) : barcode);
: barcode);
Length
SubString
DemoLabel.Text = order.ToString() + ": " + barcode;
DemoLabel.Text = order.ToString() + ": " + barcode.Substring(barcode.Length - 10, 10);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)