Ask a question: in the receiving system, scanning a barcode with a scanner is often used to input the barcode to TextBox. When the barcode cannot be scanned, manual input is required. If the scanner is used for input, we will automatically interpret the bar code. When manually input the scanner, we need to press the Enter key to confirm and then interpret the bar code. At this time, we need to determine whether the input device is a manual or scanning gun.
Method:
1. Set the TextBox attribute to ReadOnly = true. Result: no input is allowed.
2. Set attribute e. handle = true in the KeyPress event of TextBox. Result: The KeyPress event is also triggered when the scanner is input. Therefore, the KeyPress event cannot be input.
3. Determine the result in the ValueChanged event of TextBox. Result: The scanner is also a single character input, instead of inputting the entire barcode at a time.
Thinking: The scanner is actually similar to the keyboard in terms of input. However, the difference between manual input and scanning device input is that scanning device input speed is faster and the interval is average.
Lab:
The inference from the experiment results.
Solution:
Private DateTime _ dt = DateTime. Now; // defines a member function to save each time point.
Private void textBox1_KeyPress (object sender, KeyPressEventArgs e)
{
DateTime tempDt = DateTime. Now; // save the time when the key is pressed.
TimeSpan ts = tempDt. Subtract (_ dt); // obtain the time interval
If (ts. Milliseconds> 50) // determines the interval. if the interval is greater than 50 Milliseconds, the TextBox is cleared.
TextBox1.Text = "";
Dt = tempDt;
}
Now, the problem is solved. I hope you can leave a message in a better way.
From: Learning blog of yyknight