我的PDA上有条码扫描装置,旁边有开关,当按动时会发出红色的光用来扫描条码.我的问题是,如何读取扫描后读到的数据,并显示在textBox里面!条码扫描跟键盘输入的原理一样,就是多个回车,如何捕捉呢?
我的显示数据代码写到textBox1_KeyDown事件里还是textBox1_KeyPress事件里?
判断回车后如何在textBox显示?
if   (   e.KeyChar   ==   (char)13) 
{
         textBox1.text=???????
}
在textBox1.text中显示扫描的数据,问号处如何写?

解决方案 »

  1.   

    你的条形码扫描装置不提供API?
      

  2.   

    string str=string.emptyprivate void textBox1_KeyPress()
    {
    if   (   e.KeyChar   ==   (char)13)  

             textBox1.text=??????? 
              str="";

    else
       str=str+e.KeyCode.tostring();
    }
      

  3.   

    // barCode 条形码的下面的数字
        private void CreateBarCodeImage(string barCode)
        {
            if (barCode == null || barCode.Trim() == String.Empty)
                return;        System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((decimal)(barCode.Length * 11)), 20);
            Graphics g = Graphics.FromImage(image);        try
            {
                //生成随机生成器
                //Random random = new Random();            //清空图片背景色
                g.Clear(Color.White);            Font font = new System.Drawing.Font("C39HrP24DhTt", 12f); //C39HrP24DhTt是条形码
                System.Drawing.Brush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Black, Color.Black,0.0f);
                //System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Black, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
                g.DrawString(barCode, font, brush, 2, 2);            //画图片的边框线
                //g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);            System.IO.MemoryStream ms = new System.IO.MemoryStream();
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                Response.ClearContent();
                Response.ContentType = "image/Gif";
                Response.BinaryWrite(ms.ToArray());
            }
            finally
            {
                g.Dispose();
                image.Dispose();
            }
      

  4.   

    我的是symbol MC50,有SDK的,按下扫描键会触发ReadNotify事件,在这个事件里编程。
    不知道楼主的型号。
      

  5.   

    我的型号是  Pocket PC PHL 5000 Series 不知道是否有触发事件`
      

  6.   

    使用了一下2楼朋友的代码,稍微改动了一下:
    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
       string str = string.Empty;
       if (e.KeyChar == (char)13)
       {
          textBox1.Text = "";
          str = "";
       }
       else
       {
          str = str + e.KeyChar.ToString(); 
       }
       textBox1.Text = str;
    }
    运行时发现textBox1_KeyPress事件执行了很多次,也就是扫描的条码有几位,此事件就执行几次,每次取一位,如条码为9787121014765共13位,textBox1_KeyPress事件就执行13次,每次取一个数字,取完为止.
    到此为止我的问题解决了,不知道还有其他更好的方法没有?