打印不生成c# [英] Print not Generate c#
问题描述
protected void btnsave_Click(object sender,EventArgs e)
{
// string s =你好; //依赖于设备的字符串,需要一个FormFeed?
string ss =^ XA+^ FO100+100 ^ BY7+NFD123456 ^ FS+^ XZ; < br $>
//字符串命令=N+(字符串)Keys.LineFeed +A280,20,1,2,1,1,N,\代码:\+(char)Keys.LineFeed +
//A255,20,1,3,1,1,N,\+1234+\ +(char)Keys.LineFeed +
//P1+(char)Keys.LineFeed;
//创建带命令的缓冲区
StringBuilder sb = new StringBuilder();
sb.AppendLine() ;
sb.AppendLine(N);
sb.AppendLine(q609);
sb.AppendLine(Q203, 26);
sb.AppendLine(string.Format(
CultureInfo.InvariantCulture,
B26,26,0,UA0,2 ,2,152,B,\{0} \,
this.upc));
sb.AppendLine(P1,1); < br $> b $ b
// Byte [] buffer = new byte [ss.Length];
// buffer = System.Text.Encoding.ASCII.GetBytes(ss);
// //允许用户选择打印机。
PrintDialog pd1 = new PrintDialog();
pd1.PrinterSettings = new PrinterSettings();
if(DialogResult.OK == pd1.ShowDialog())
{
//发送特定于打印机的打印机。
PrintRaw.SendStringToPrinter(pd1.PrinterSettings.PrinterName,sb.ToString());
}
}
方法调用此方法(PrintRaw.SendStringToPrinter(pd1.PrinterSettings.PrinterName,sb.ToString) ());)
Hi,
protected void btnsave_Click(object sender, EventArgs e)
{
//string s = "Hello"; // device-dependent string, need a FormFeed?
string ss = "^XA"+"^FO100"+"100^BY7"+"NFD123456^FS"+"^XZ";
//string command = "N" + (char)Keys.LineFeed + "A280,20,1,2,1,1,N,\"CODE:\"" + (char)Keys.LineFeed +
//"A255,20,1,3,1,1,N,\"" + "1234" + "\"" + (char)Keys.LineFeed +
//"P1" + (char)Keys.LineFeed;
// Create a buffer with the command
StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("N");
sb.AppendLine("q609");
sb.AppendLine("Q203,26");
sb.AppendLine(string.Format(
CultureInfo.InvariantCulture,
"B26,26,0,UA0,2,2,152,B,\"{0}\"",
this.upc));
sb.AppendLine("P1,1");
//Byte[] buffer = new byte[ss.Length];
//buffer = System.Text.Encoding.ASCII.GetBytes(ss);
//// Allow the user to select a printer.
PrintDialog pd1 = new PrintDialog();
pd1.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd1.ShowDialog())
{
// Send a printer-specific to the printer.
PrintRaw.SendStringToPrinter(pd1.PrinterSettings.PrinterName, sb.ToString());
}
}
method call this (PrintRaw.SendStringToPrinter(pd1.PrinterSettings.PrinterName, sb.ToString());)
public static bool SendStringToPrinter(string szPrinterName, string szString)
{
IntPtr pBytes;
Int32 dwCount;
// How many characters are in the string?
dwCount = szString.Length;
// Assume that the printer is expecting ANSI text, and then convert
// the string to ANSI text.
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
// Send the converted ANSI string to the printer.
SendBytesToPrinter(szPrinterName, pBytes, dwCount);
Marshal.FreeCoTaskMem(pBytes);
return true;
}
但是没有在打印机中打印
but not getting print in printer
推荐答案
您在代码中编写了
SendBytesToPrinter(szPrinterName, pBytes, dwCount);
。这个功能是做什么的。请告诉我们,以便我们更好地理解这个问题。
in your code. what that function does. Please tell us so that we can understand the issue better.
这篇关于打印不生成c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!