c# - 使用 C# 在数据逻辑存储器设备上按下扫描按钮时的替代事件

标签 c# .net barcode-scanner keyevent

我将 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/

相关文章:

java - 在 Android 应用程序中使用 zxing 扫描条形码阅读器数据

VBA 和 GetRawInputDeviceList

c# - C# 是否支持可变数量的参数,如何支持?

c# - 使用 Oledb 导出到没有标题的 excel 文件 c#

c# - WCF4 (.NET Framework 4) 是否支持客户端连接池?

c# - ToUniversalTime() 和 ToLocalTime() 之间的区别

.net - NuGet(NuPack)智能感知(Visual Studio程序包管理器控制台)

android - React native,二维码扫描部分设备黑屏

c# - OpenTK 中的立方体贴图

c# - 二进制搜索算法查找排序数组中值的变化