首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

打印机命令输出!

2012-01-02 
高分求教打印机命令输出!!厂商提供打印机切纸命令VB6.0实现Print#1,Chr$(&H1B)Chr$(&H64)Chr$(&H0)切纸

高分求教打印机命令输出!!
厂商提供打印机切纸命令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();


                                CloseHandle(ptr);
                        }
                        catch   (Exception   ex)
                        {
                                MessageBox.Show(Convert.ToString(ex));
                        }
                }
如何在C#中实现

多谢大家!!

[解决办法]

[解决办法]
// StreamWriter没有WriteLine方法吧
// byte[] buffer = System.Text.Encoding.Default.GetBytes(Instruction); 不用吧

sw.Write(Instruction);
[解决办法]
string Instruction = null;
Instruction = Convert.ToChar(27) + Instruction + Convert.ToChar(100) + Instruction + Convert.ToChar(0);
sw.WriteLine(Instruction);

热点排行