c# 小票机打印二维条码_C# winform小票打印

(1)自定义纸张设置

控制面板->打印机和传真->右键->服务器属性->创建新的格式

(2)自定义纸张使用

this.printDocument1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("NewPrint", iWidth, iHeight);

NewPrint:制定一纸张名称。 iWidth:纸张使用宽度。 iHeight:纸张使用高度。

iWidth,iHeight 可以在使用过程中调整。

例如:iWidth=923,iHeight=480

(3)ESC/P指令使用

using System;

using System.Runtime.InteropServices;

using System.Data;

using System.IO;

using System.Windows.Forms;

namespace PrintDome

{

class ClsPrintLPT

{

private IntPtr iHandle;

private FileStream fs;

private StreamWriter sw;

private string prnPort = "LPT1"; //打印机端口

public ClsPrintLPT()

{

}

private const uint GENERIC_READ = 0x80000000;

private const uint GENERIC_WRITE = 0x40000000;

private const int OPEN_EXISTING = 3;

///

/// 打开一个vxd(设备)

///

[DllImport("kernel32.dll", EntryPoint = "CreateFile", CharSet = CharSet.Auto)]

private static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, int dwShareMode, int lpSecurityAttributes,

int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile);

///

/// 开始连接打印机

///

private bool PrintOpen()

{

iHandle = CreateFile(prnPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);

if (iHandle.ToInt32() == -1)

{

MessageBox.Show("没有连接打印机或者打印机端口不是LPT1!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

return false;

}

else

{

fs = new FileStream(iHandle, FileAccess.ReadWrite);

sw = new StreamWriter(fs, System.Text.Encoding.Default); //写数据

return true;

}

}

///

/// 打印字符串

///

/// 要打印的字符串

private void PrintLine(string str)

{

sw.WriteLine(str); ;

}

///

/// 关闭打印连接

///

private void PrintEnd()

{

sw.Close();

fs.Close();

}

///

/// 打印票据

///

/// tb_Temp 全部字段数据集合

/// true:打印成功 false:打印失败

public bool PrintDataSet(DataSet dsPrint)

{

try

{

if (PrintOpen())

{

PrintLine(" ");

PrintLine("[XXXXXXXXXXXXXXXXXX超市]"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值