• 大小: 419KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: C#
  • 标签: c#扫码枪  

资源简介

目前经过百度搜索的资料经过测试都不稳定,这是找到的最稳定有效的版本。代码易懂,方便修改。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Text.Regularexpressions;

namespace LoadMaterial
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();


        }

        private void FormMain_Load(object sender EventArgs e)
        {

        } 
        
      

        private void btnScan_Click(object sender EventArgs e)
        {
            OnScan(txtBarcode.Text);

        } 


        DateTime _lastTime = DateTime.Now.AddDays(-1);
        void OnScan(String barcode)
        {

            if ((DateTime.Now - _lastTime).TotalMilliseconds < 50)
            {
                _lastTime = DateTime.Now;
                return;
            }
            _lastTime = DateTime.Now;

            if (txtBarcode.Text != barcode)
                txtBarcode.Text = barcode;


            richTextBox1.Text = richTextBox1.Text + barcode + “\n“;

            txtBarcode.Text = ““;
        }
        


        #region USB Scanner

        Keys _spaceKey = Keys.None;
        private DateTime _beginTime = DateTime.MinValue;
        private String _barcode = ““;
        private int _minbarcodelength = 3;

        private void tsmiExit_Click(object sender EventArgs e)
        {
            Close();
        }


        private bool CheckValide(object sender KeyEventArgs e)
        {

            if (sender is TextBox)
            {
                TextBox txt = sender as TextBox;

                if (!txt.ReadOnly)
                    return false;
            }
           /*  
        else
        {
            if (e.IsRepeat)
            {
                e.Handled = true;
                return false;
            }
        }  */

            return true;

        }
        

        private void FormMain_KeyDown(object sender KeyEventArgs e)
        {

            if (!CheckValide(sender e))
            {
                _beginTime = DateTime.MinValue;
                _barcode = ““;
                return;
            }

            if (!tmKey.Enabled)
                tmKey.Enabled = true;

            if (e.KeyCode == Keys.Return)
            {
                //如果是按钮,则结束事件传递,防止触发按钮点击事件
                if (sender is Button)
                    e.Handled = true;

                tmKey.Enabled = false;

                if (_barcode.Length >= _minbarcodelength)
                {
                    OnScan(_barcode.Replace(‘\r‘ ‘ ‘).Trim());
                }
                _beginTime = DateTime.MinValue;
                _barcode = ““;
                return;
            }
            
            if (e.KeyCode == Keys.Space)
            {
                _spaceKey = e.KeyCode;
            }


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     65024  2018-03-29 00:56  6199186TestUSBScan\TestUSBScan\.vs\LoadMaterial\v15\.suo

     文件       4628  2014-03-31 15:21  6199186TestUSBScan\TestUSBScan\Backup\FormMain.cs

     文件       4319  2014-03-31 15:18  6199186TestUSBScan\TestUSBScan\Backup\FormMain.Designer.cs

     文件       6008  2014-03-31 15:18  6199186TestUSBScan\TestUSBScan\Backup\FormMain.resx

     文件       4090  2014-03-31 15:20  6199186TestUSBScan\TestUSBScan\Backup\LoadMaterial.csproj

     文件        913  2014-03-21 12:24  6199186TestUSBScan\TestUSBScan\Backup\LoadMaterial.sln

     文件        522  2014-03-31 15:21  6199186TestUSBScan\TestUSBScan\Backup\Program.cs

     文件       1356  2014-03-21 12:24  6199186TestUSBScan\TestUSBScan\Backup\Properties\AssemblyInfo.cs

     文件       2848  2014-03-31 15:20  6199186TestUSBScan\TestUSBScan\Backup\Properties\Resources.Designer.cs

     文件       5817  2014-03-31 15:20  6199186TestUSBScan\TestUSBScan\Backup\Properties\Resources.resx

     文件       1097  2014-03-21 12:24  6199186TestUSBScan\TestUSBScan\Backup\Properties\Settings.Designer.cs

     文件        249  2014-03-21 12:23  6199186TestUSBScan\TestUSBScan\Backup\Properties\Settings.settings

     文件      11264  2018-03-28 23:33  6199186TestUSBScan\TestUSBScan\bin\Debug\LoadMaterial.exe

     文件      22016  2018-03-28 23:33  6199186TestUSBScan\TestUSBScan\bin\Debug\LoadMaterial.pdb

     文件      14848  2014-03-31 15:23  6199186TestUSBScan\TestUSBScan\bin\Debug\LoadMaterial.vshost.exe

     文件        490  2012-06-02 22:33  6199186TestUSBScan\TestUSBScan\bin\Debug\LoadMaterial.vshost.exe.manifest

     文件    1276720  2007-10-10 10:49  6199186TestUSBScan\TestUSBScan\bin\Debug\Microsoft.Office.Interop.Excel.dll

     文件      64288  2007-10-10 10:49  6199186TestUSBScan\TestUSBScan\bin\Debug\Microsoft.Vbe.Interop.dll

     文件     416544  2007-10-10 10:49  6199186TestUSBScan\TestUSBScan\bin\Debug\office.dll

     文件      22344  2010-03-18 23:21  6199186TestUSBScan\TestUSBScan\bin\Debug\stdole.dll

     文件       4628  2018-03-28 23:33  6199186TestUSBScan\TestUSBScan\FormMain.cs

     文件       4319  2014-03-31 15:18  6199186TestUSBScan\TestUSBScan\FormMain.Designer.cs

     文件       6008  2014-03-31 15:18  6199186TestUSBScan\TestUSBScan\FormMain.resx

     文件       4243  2018-03-27 22:19  6199186TestUSBScan\TestUSBScan\LoadMaterial.csproj

     文件        990  2018-03-27 22:19  6199186TestUSBScan\TestUSBScan\LoadMaterial.sln

    ..A..H.     30208  2014-03-31 15:23  6199186TestUSBScan\TestUSBScan\LoadMaterial.suo

     文件         42  2018-03-27 22:19  6199186TestUSBScan\TestUSBScan\obj\Debug\CoreCompileInputs.cache

     文件        790  2018-04-06 21:49  6199186TestUSBScan\TestUSBScan\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7000  2018-04-06 21:49  6199186TestUSBScan\TestUSBScan\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       2610  2018-03-27 22:19  6199186TestUSBScan\TestUSBScan\obj\Debug\LoadMaterial.csproj.FileListAbsolute.txt

............此处省略36个文件信息

评论

共有 条评论

相关资源