十万火急, 客户催得我想跳楼这是我的打印代码 public PrintDocument pdDocument;
public PageSetupDialog dlgPageSetup;
public PrintPreviewDialog ppd;
public PrintDialog pd;
private string[] lines; public string[] Lines
{
get
{
if (ViewState["Lines"] != null)
return ViewState["Lines"] as string[];
return null;
}
set
{
lines = value;
ViewState["Lines"] = lines;
}
} public PrintHelper()
{
pdDocument = new PrintDocument();
dlgPageSetup = new PageSetupDialog();
ppd = new PrintPreviewDialog();
pd = new PrintDialog();
dlgPageSetup.Document = pdDocument;
pd.Document = pdDocument;
ppd.Document = pdDocument;
pdDocument.PrintPage += new PrintPageEventHandler(pdDocument_PrintPage);
pdDocument.BeginPrint += new PrintEventHandler(pdDocument_BeginPrint);
pdDocument.EndPrint += new PrintEventHandler(pdDocument_EndPrint);
} void pdDocument_EndPrint(object sender, PrintEventArgs e)
{
lines = null;
} void pdDocument_BeginPrint(object sender, PrintEventArgs e)
{ } /// <summary>
/// 开始打印
/// </summary>
public void Print()
{
try
{
pdDocument.Print();
}
catch (InvalidPrinterException ex)
{
File.WriteAllText("c://test.txt", ex.Message, Encoding.UTF8);
}
}
void pdDocument_PrintPage(object sender, PrintPageEventArgs e)
{
int x = 20;
int y = 20;
int count = 0;
while (count < Lines.Length)
{
e.Graphics.DrawString(Lines[count], new Font("微软雅黑", 20), System.Drawing.Brushes.Black, x, y);
y += 50;
count++;
}
count = 0;
e.HasMorePages = false;
}
打印机用的佳博GP-7635III 76m针式打印机。
无奈无论如何也打印不出来。求高手指点 !!!
public PageSetupDialog dlgPageSetup;
public PrintPreviewDialog ppd;
public PrintDialog pd;
private string[] lines; public string[] Lines
{
get
{
if (ViewState["Lines"] != null)
return ViewState["Lines"] as string[];
return null;
}
set
{
lines = value;
ViewState["Lines"] = lines;
}
} public PrintHelper()
{
pdDocument = new PrintDocument();
dlgPageSetup = new PageSetupDialog();
ppd = new PrintPreviewDialog();
pd = new PrintDialog();
dlgPageSetup.Document = pdDocument;
pd.Document = pdDocument;
ppd.Document = pdDocument;
pdDocument.PrintPage += new PrintPageEventHandler(pdDocument_PrintPage);
pdDocument.BeginPrint += new PrintEventHandler(pdDocument_BeginPrint);
pdDocument.EndPrint += new PrintEventHandler(pdDocument_EndPrint);
} void pdDocument_EndPrint(object sender, PrintEventArgs e)
{
lines = null;
} void pdDocument_BeginPrint(object sender, PrintEventArgs e)
{ } /// <summary>
/// 开始打印
/// </summary>
public void Print()
{
try
{
pdDocument.Print();
}
catch (InvalidPrinterException ex)
{
File.WriteAllText("c://test.txt", ex.Message, Encoding.UTF8);
}
}
void pdDocument_PrintPage(object sender, PrintPageEventArgs e)
{
int x = 20;
int y = 20;
int count = 0;
while (count < Lines.Length)
{
e.Graphics.DrawString(Lines[count], new Font("微软雅黑", 20), System.Drawing.Brushes.Black, x, y);
y += 50;
count++;
}
count = 0;
e.HasMorePages = false;
}
打印机用的佳博GP-7635III 76m针式打印机。
无奈无论如何也打印不出来。求高手指点 !!!
解决方案 »
- 中控二次开发 zkemkeeper ref out
- Microsoft.Practices.EnterpriseLibrary 配置数据库连接的问题,请各位 帮帮忙
- SharpDevelop的朋友请进
- WPF TreeView问题~急~
- .net的C#可不可以动态创建函数?
- 如何判断多行文本框中已经输入多少行?
- 关于采用socket通过Server Push(推技术)来建立聊天室的一些疑问,高手进来指点一二。
- 代码转换
- ASP.NET使用Dictionary出错
- 使用PrintDocument出现问题
- 未能找到与传递给事件绑定服务的对象关联的网站,因此无法在该对象上设置事件。
- c# wince下实现将pictureBox中的图片转换成html文件保存到固定路径
楼主先用WORK或EXCEL软件打印一下,确认打印机有没有问题