我将 C# 2003 用于 Datalogic Memor 应用程序。我研究过按下设备的“扫描按钮”时会触发 KeyPress 事件。捕获它是 if(e.KeyChar == 13)
但它不起作用。有其他替代方案吗?
最佳答案
尝试安装 Datalogic SDK 2_0_0_0 您可以从Datalogic 下载。网站。
然后添加对数据逻辑 API 的引用:
C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\Datalogic.API.dll
现在您可以通过这种方式使用 API:
在您的表单声明中:
private DecodeEvent dcdEvent;
private DecodeHandle hDcd;
在您的表单加载事件中:
// Attempt to load a handle to the decoder.
try
{
hDcd = new DecodeHandle(DecodeDeviceCap.Exists | DecodeDeviceCap.Barcode);
}
catch(DecodeException)
{
MessageBox.Show("Exception loading barcode decoder.", "Decoder Error");
return;
}
// Now that we've got a connection to a barcode reading device, assign a
// method for the DcdEvent. A recurring request is used so that we will
// continue to get barcode data until our dialog is closed.
DecodeRequest reqType = (DecodeRequest)1 | DecodeRequest.PostRecurring;
// Initialize all events possible
//dcdEvent = new DecodeEvent(hDcd, reqType);
dcdEvent = new DecodeEvent(hDcd, reqType, this);
dcdEvent.Scanned += new DecodeScanned(dcdEvent_Scanned);
这是您的事件监听器:
private void dcdEvent_Scanned(object sender, DecodeEventArgs e)
{
CodeId cID = CodeId.NoData;
string dcdData = string.Empty;
// Obtain the string and code id.
try
{
dcdData = hDcd.ReadString(e.RequestID, ref cID);
}
catch(Exception)
{
MessageBox.Show("Error reading string!");
return;
}
string result = "Barcode Text: " + dcdData;
result +=" AND Barcode Code Id : " + cID.ToString();
MessageBox.Show(result);
}
在您的表单关闭事件中:
if(dcdEvent.IsListening)
{
dcdEvent.StopScanListener();
}
if (hDcd != null)
{
hDcd.Dispose();
}
关于c# - 使用 C# 在数据逻辑存储器设备上按下扫描按钮时的替代事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9059951/