代码出自票据打印类:http://www.csharpwin.com/csharpspace/9090r8371.shtml
代码片段如下:
public void Print(string str, string align)
        {
            if (TicketPrinterHandle == null)
                return;
            if (TicketPrinterHandle.IsInvalid)
                return;
            int PadCount = 30;
            PadCount -= StrLen(str);
            if (align == "center")
                str = str.PadLeft(PadCount / 2 + str.Length, ' ');
            else if (align == "right")
                str = str.PadLeft(PadCount,' ');

            int RetryCount = 10;
        Retry:
            int sta = 0;
            if (_PPort == "LPT1")
                sta = Input(0x379);
            else if (_PPort == "LPT2")
                sta = Input(0x279);

            if (sta == 0x7F)
         
   {
                Status = "未连接";
                return;
            }            if ((sta & 0x10) == 0)
            {
                Status = "未上电";
                return;
            }            if((sta&0x80)==0)
            {
                Status = "打印机忙";
                RetryCount--;
                if (RetryCount <= 0)
                    return;
                goto Retry;
            }            if((sta&0x20)!=0)
            {
                Status = "打印机缺纸";
                return;
            }        }

解决方案 »

  1.   

    问题一:这段代码的功能是什么?
    问题3:“PadLeft”是个什么方法,作用是什么?
    问题4:这段代码的作用是什么?
    问题五:为什么“sta == 0x7F”,其中的“0x7F”表示什么?
      

  2.   

    问题2:类中没有方法“StrLen”,在下实在疑惑它是从哪里来的。引用中也没有,它应该是怎样写的?
      

  3.   

    strlen()函数的反回类型为unsigned int(无符号整型)
    在.net中,可以使用String.PadLeft函数右对齐字符串,在左边用指定的Unicode字符填充一达到指定的总长度。
           例如 在做自动编号这样使用
         int nextID=da.GetMaxNum()+1;
         this.txtCode.Text = nextID.ToString().PadLeft(6, '0');