日期:2014-05-20  浏览次数:20871 次

高分求教打印机命令输出!!
厂商提供打印机切纸命令VB6.0实现

Print   #1,   Chr$(&H1B);   Chr$(&H64);   Chr$(&H0);       '切纸命令

//------------------------------------------------------
//以下是C#向打印机输出命令

[DllImport( "Kernel32.dll ")]
                static   extern   IntPtr   CreateFile(
                        string   filename,
                        [MarshalAs(UnmanagedType.U4)]FileAccess   fileaccess,
                        [MarshalAs(UnmanagedType.U4)]FileShare   fileshare,
                        int   securityattributes,
                        [MarshalAs(UnmanagedType.U4)]FileMode   creationdisposition,
                        int   flags,
                        IntPtr   template);

                [DllImport( "kernel32.dll ")]
                static   extern   bool   CloseHandle(IntPtr   hObject);

private   void   btncut_Click(object   sender,   EventArgs   e)
                {
                        try
                        {
                                SafeFileHandle   sfh   =   null;
                                IntPtr   ptr   =   CreateFile( "PRN ",   FileAccess.Write,   FileShare.Write,   0,   FileMode.Open,   0,   IntPtr.Zero);
                                sfh   =   new   SafeFileHandle(ptr,   true);
                                StreamWriter   sw   =   new   StreamWriter(new   FileStream(sfh,   FileAccess.Write));
                                string   Instruction   =   null;
                                Instruction   =   Convert.ToChar(27)   +   Instruction   +   Convert.ToChar(100)   +   Instruction   +   Convert.ToChar(0);
                                byte[]   buffer   =   System.Text.Encoding.Default.GetBytes(Instruction);
                                sw.WriteLine(打印机命令);     ------------如何填写?
                                sw.Close();