Gra*_*ter 0 c# events credit-card winforms
我正在使用测试卡,这是我刷卡后的输出,没关系

但是,当我试图获取刷过的数据提示它到消息框时,这将是输出

我怎样才能解决这个问题?我期望输出与第一张图像相同,它也将是消息框的消息
这是我的代码:
private void CreditCardProcessor_Load(object sender, EventArgs e)
{
KeyPreview = true;
KeyPress += CreditCardProcessor_KeyPress;
}
private bool inputToLabel = true;
private void CreditCardProcessor_KeyPress(object sender, KeyPressEventArgs e)
{
if (inputToLabel)
{
label13.Text = label13.Text + e.KeyChar;
e.Handled = true;
}
else
{
e.Handled = false;
}
MessageBox.Show(label13.Text);
}
Run Code Online (Sandbox Code Playgroud)
简而言之,我想在刷卡后运行一个功能,并使用其数据在我的功能中使用.:)
你需要更具体地回答你的问题.从卡片扫描仪通过键盘缓冲区操作的外观.(许多卡片扫描仪以这种方式操作)这意味着条带的每个字符都作为字符被接收,这就是为什么你可以捕获它OnKeyPress.
如果你想知道为什么你一次只看到一个角色,那正是因为你正在提出一个收到每个角色的消息框.如果您想知道何时可以使用该代码使用整个卡信息调用函数,您需要的是:
private bool inputToLabel = true;
private StringBuilder cardData = new StringBuilder();
private void CreditCardProcessor_KeyPress(object sender, KeyPressEventArgs e)
{
if (!inputToLabel)
return;
if (e.KeyChar == '\r')
{
MessageBox.Show(cardData.ToString()); // Call your method here.
}
else
{
cardData.Append(e.KeyChar);
//label13.Text = label13.Text + e.KeyChar;
}
e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
警告:这是假设读卡器库配置为使用回车终止卡读取.(\ r \n)您需要阅读或试验它,以确定它是否能够/确实发送终止字符以了解读卡完成的时间.如果失败,您可以观看模式的输出字符串.(即当捕获的字符串以"??"结束时)虽然这不是最佳的.