public partial class Form1 : Form { DateTime _lastKeystroke = new DateTime(0); List<char> _barcode = new List<char>(10); public Form1() { InitializeComponent(); } private void Form1_KeyPress(object sender, KeyPressEventArgs e) { TimeSpan elapsed = (DateTime.Now - _lastKeystroke); if (elapsed.TotalMilliseconds > 100) _barcode.Clear(); // record keystroke & timestamp _barcode.Add(e.KeyChar); _lastKeystroke = DateTime.Now; // process barcode if (e.KeyChar == 13 && _barcode.Count > 0) { string msg = new String(_barcode.ToArray()); string[] lines = msg.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); if (lines.Length > 5) { string msg1 = lines[1].Substring(lines[1].IndexOf(":") + 1); label3.Text = msg1; string msg2 = lines[2].Substring(lines[2].IndexOf(":") + 1); label4.Text = msg2; string msg3 = lines[3].Substring(lines[3].IndexOf(":") + 1); label5.Text = msg3; string msg4 = lines[4].Substring(lines[4].IndexOf(":") + 1); label6.Text = msg4; label2.Text = lines[5].Substring(lines[5].IndexOf(":") + 1); } _barcode.Clear(); } } } }
when split msg variable to more lines it not give me values in lines?
Environment.NewLine
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)