谁知道System.Drawing.Printing.PrintEventArgs怎么用?

nobounded 2003-11-07 10:08:06
谁知道System.Drawing.Printing.PrintEventArgs怎么用?给些具体的例子,能不能对打印进行监视?(就是能不能得到一些打印的事件).
...全文
287 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
brightheroes 2003-12-08
  • 打赏
  • 举报
回复
try
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler( PrintInOut );
pd.Print();
}
catch
{
this.sp_description.Text = "打印失败!请检查打印机是否可用...........";
return;
}
brightheroes 2003-12-08
  • 打赏
  • 举报
回复
给你一段代码,你看看

/// <summary>
/// 打印水单
/// </summary>
/// <param name="sender"></param>
/// <param name="ev"></param>
private void PrintInOut(object sender, PrintPageEventArgs ev)
{
Font printFont;
String str, temp;
float yPos = 0;
int count = 0;
float leftMargin = 0; //ev.MarginBounds.Left;
float topMargin = 0; //ev.MarginBounds.Top;

printFont = new Font("黑体", 12);
str = "欢 迎 光 临";
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString (str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

count++; //加一空行

// printFont = new Font("黑体", 12);
// str = uncString.FillLeftSpace( this.labelShopName.Text, 20 - this.labelShopName.Text.Length );
// yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
// ev.Graphics.DrawString (str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

printFont = new Font("新宋体", 10);
str = "========================================";
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics)) + 5;
ev.Graphics.DrawString (str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

//打印流水号
str = "流水号:"+this.lb_inout_code.Text;
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

str = "----------------------------------------";
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

str = " 品名 单价 数量 折扣 金额";
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

str = "----------------------------------------";
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
foreach(DataRow dr in this.dtInout.Rows)
{
str = dr["item_name"].ToString(); //打印品名
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str , printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
if(dr["item_discount"].ToString() == "100")
{
temp = " ";
}
else
{
temp = uncString.FillLeftSpace(dr["item_discount"].ToString(),5);
}
//打印单价、数量、折扣、金额
str = " " +
uncString.FillLeftSpace( dr["item_price"].ToString(), 7 ) +
uncString.FillLeftSpace( dr["item_qty"].ToString(), 7 ) +
temp +
uncString.FillLeftSpace( dr["item_amount"].ToString(), 10 );
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str , printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

}

str = "----------------------------------------";
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

str = " 合计: " +
uncString.FillLeftSpace( this.lb_act_amount.Text.ToString(), 11 );
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str , printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
str = " 收银: " +
uncString.FillLeftSpace(this.tb_Money.Text.ToString(), 11 );
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str , printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

if ( this.lb_change.Text != "0.00" )
{
str = " 找零: " +
uncString.FillLeftSpace( this.lb_change.Text, 11 );
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str , printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
}

count++; //加一空行

str = DateTime.Now.ToString( "yyyy.MM.dd HH:mm:ss" );
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

//滚动6行
count += 5;
str = " ";
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

}
nobounded 2003-12-05
  • 打赏
  • 举报
回复
打印监视器类?什么东西,哪有?
ansonzts 2003-11-08
  • 打赏
  • 举报
回复
刚做完打印,感觉System.Drawing.Printing.PrintEventArgs很有用,通过该事件类,可以获得打印的区域,打印的graphics对象。对打印进行监视觉得不行,可以用打印监视器类来实现。
513 2003-11-08
  • 打赏
  • 举报
回复
PrintPage事件
这里有个例子
ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfsystemdrawingprintingprintdocumentclasstopic.htm
chenshi999 2003-11-08
  • 打赏
  • 举报
回复
对打印进行好好的控制,需要自行继承编辑PrintController子类。
wangke1220 2003-11-07
  • 打赏
  • 举报
回复
up

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧