C# 使用printDocument1.Print打印时不显示 正在打印对话框

本文介绍了在C#中使用PrintController和设置窗体属性来避免打印时不显示正在打印对话框的两种方法。通过实例演示了如何实现这些解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C#使用printDocument1.Print打印时不显示正在打印对话框有两种方法

第一种,使用PrintController

      PrintController printController = new StandardPrintController();
      printDocument1.PrintController = printController;
      printDocument1.Print();

第二种,把窗体的TopMost设为True

转载于:https://www.cnblogs.com/chendaoyin/p/3194011.html

打印方法小议,页面设置对话框打印预览对话框打印对话框等功能,C#源代码 //字符串流对 象,一行一行读取文本 private StringReader MyReader; private void button1_Click(object sender, EventArgs e) { //显示页面设置对话框 PageSetupDialog MyDlg = new PageSetupDialog(); MyDlg.Document = this.printDocument1; MyDlg.ShowDialog(); } private void button2_Click(object sender, EventArgs e) { //显示打印预览对话框 PrintPreviewDialog MyDlg = new PrintPreviewDialog(); MyDlg.Document = this.printDocument1; this.MyReader = new StringReader(this.richTextBox1.Text); MyDlg.ShowDialog(); } private void button3_Click(object sender, EventArgs e) { //显示打印对话框 PrintDialog MyDlg = new PrintDialog(); MyDlg.Document = this.printDocument1; MyDlg.ShowDialog(); } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Graphics g = e.Graphics; //每一页的行数 float MyLines = e.MarginBounds.Height / this.richTextBox1.Font.GetHeight (g); //打印的行计数器 int MyLineNumber = 0; //打印的纵坐标 float MyYPosition = 0; float MyMarginLeft = e.MarginBounds.Left; float MyMarginTop = e.MarginBounds.Top; //每一行要打印的文本 string MyLine = ""; while ((MyLineNumber < MyLines) && ((MyLine = MyReader.ReadLine()) != null)) { MyYPosition = MyMarginTop + MyLineNumber * this.richTextBox1.Font.GetHeight(g); g.DrawString(MyLine, this.richTextBox1.Font, new SolidBrush (Color.Black), MyMarginLeft, MyYPosition, new StringFormat()); MyLineNumber++; } if (MyLine != null) { //发出下一次PrintPage事件 e.HasMorePages = true; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值