Barcode reader can be configured to automatically send a [Enter] after it reads a barcode.
With the [Enter] key stroke detected in textBox1, cache the code in a private string value within the class.
Whenever any method wants to access the barcode value, get it from the private string.
Example:
public partial class Form2 : Form
{
string lastScannedCode = "";
public Form2()
{
InitializeComponent();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
lastScannedCode = textBox1.Text;
label1.Text = lastScannedCode;
textBox1.Clear();
}
}
void ShowTheLastScannedCode()
{
MessageBox.Show(lastScannedCode);
}
}