高分求教打印机命令输出!!

CN_Azure 2007-03-08 09:53:34
厂商提供打印机切纸命令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#中实现

多谢大家!!
...全文
253 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
mhjmhj2000 2007-03-08
  • 打赏
  • 举报
回复
string Instruction = null;
Instruction = Convert.ToChar(27) + Instruction + Convert.ToChar(100) + Instruction + Convert.ToChar(0);
sw.WriteLine(Instruction);
CN_Azure 2007-03-08
  • 打赏
  • 举报
回复
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(buffer);

这个我试过的。不行,没有切纸,直接打印出来了。打印的结果是System.Byte[]

csShooter 2007-03-08
  • 打赏
  • 举报
回复
// StreamWriter没有WriteLine方法吧
// byte[] buffer = System.Text.Encoding.Default.GetBytes(Instruction); 不用吧

sw.Write(Instruction);

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧