如下:
QtSz qtsz = new QtSz();
string dpmc = QtSz.scmc;
const int OPEN_EXISTING = 3;
string prnPort = "LPT1";
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr CreateFile(string lpFileName,
int dwDesiredAccess,
int dwShareMode,
int lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
int hTemplateFile);
QT qt11 = new QT("LPT1");
//string str=qt11.PrintLine("");
IntPtr iHandle1 = CreateFile(prnPort, 0x50000000, 0, 0, OPEN_EXISTING, 0, 0);
if (iHandle1.ToInt32() == -1)
{
Console.WriteLine(iHandle1.ToString());
//return "没有连接打印机或者打印机端口不是LPT1";
}
else
{
Console.WriteLine(iHandle1.ToString());
FileStream fs = new FileStream(iHandle1, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
//PrintEsc(1);
//sw.WriteLine(str);
//开钱箱指令
sw.Write(((char)27).ToString() + "p" + ((char)0).ToString() + ((char)60).ToString() + ((char)255).ToString());
//打印小票头
sw.Write(" \t"); sw.WriteLine(shangdianmingcheng);
sw.Write(" \t"); sw.WriteLine(biaotou);
sw.Write("电话:"); sw.WriteLine(dianhua); sw.Write("地址;"); sw.WriteLine(dizhi);
sw.Write("销售时间:"); sw.WriteLine(Convert.ToDateTime(this.label19.Text.Trim()));
sw.Write("流水号:"); sw.WriteLine(Convert.ToString(this.label3.Text.Trim()));
sw.WriteLine();
sw.WriteLine("------------------------------");
sw.WriteLine("商品名称 数量 单价 金额");
sw.WriteLine("-------------------------------");
sw.Close();
fs.Close();
//return "打印机连接成功";
看看打印机有没有api可以用啊
要不就看看print类
你问的这么简单,我也只好很简单的回答。调用打印的API,详情看打印机说明,并查看MSDN