我在网上下了个打印程序,如下
protected void Button1_Click(object sender, EventArgs e)
{
PrintDocument printDocument;
printDocument = new PrintDocument();
printDocument.PrintPage += new PrintPageEventHandler(this.printDocument_PrintPage);
}
private void printDocument_PrintPage(object sender,PrintPageEventArgs e)
{
Graphics g = e.Graphics; //获得绘图对象
float linesPerPage = 0; //页面的行号
float yPosition = 0; //绘制字符串的纵向位置
int count = 0; //行计数器
float leftMargin = e.MarginBounds.Left; //左边距
float topMargin = e.MarginBounds.Top; //上边距
string line = null; 行字符串
Font PrintFont = this.textBox.Font; //当前的打印字体
SolidBrush myBrush = new SolidBrush(Color.Black);//刷子
linesPerPage = e.MarginBounds.Height / printFont.GetHeight(g);//每页可打印的行数
//逐行的循环打印一页
while(count < linesPerPage && ((line=lineReader.ReadLine()) != null))
{
yPosition = topMargin + (count * printFont.GetHeight(g));
g.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat());
count++;
}
}
在调试时总出错
Font PrintFont = this.textBox.Font;这一行应输入;谁能帮忙看下吗,能否给我解释下这个程序啊,谢谢
protected void Button1_Click(object sender, EventArgs e)
{
PrintDocument printDocument;
printDocument = new PrintDocument();
printDocument.PrintPage += new PrintPageEventHandler(this.printDocument_PrintPage);
}
private void printDocument_PrintPage(object sender,PrintPageEventArgs e)
{
Graphics g = e.Graphics; //获得绘图对象
float linesPerPage = 0; //页面的行号
float yPosition = 0; //绘制字符串的纵向位置
int count = 0; //行计数器
float leftMargin = e.MarginBounds.Left; //左边距
float topMargin = e.MarginBounds.Top; //上边距
string line = null; 行字符串
Font PrintFont = this.textBox.Font; //当前的打印字体
SolidBrush myBrush = new SolidBrush(Color.Black);//刷子
linesPerPage = e.MarginBounds.Height / printFont.GetHeight(g);//每页可打印的行数
//逐行的循环打印一页
while(count < linesPerPage && ((line=lineReader.ReadLine()) != null))
{
yPosition = topMargin + (count * printFont.GetHeight(g));
g.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat());
count++;
}
}
在调试时总出错
Font PrintFont = this.textBox.Font;这一行应输入;谁能帮忙看下吗,能否给我解释下这个程序啊,谢谢
现在就是我按打印按扭,不执行打印操作,这是为什么呢,能指导下吗,刚接触打印.谢谢
我主要是要能实现把页面内容有选择的打印,并且格式是固定的,就想银行打印发票一样,打出的内容模版是固定的,而我打出的内要正好在那些格式中,应该选择用哪种打印方法啊 谢谢