C#编程-136:Windows打印技术

C#编程-136:Windows打印技术

C#编程-136:Windows打印技术

C#编程-136:Windows打印技术

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace PrintDialogTest
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void button1_Click(object sender, EventArgs e)
  20.         {
  21.             try
  22.             {
  23.                 pageSetupDialog1.Document = printDocument1;
  24.                 pageSetupDialog1.ShowDialog();
  25.             }
  26.             catch (Exception ex)
  27.             {
  28.  
  29.                 MessageBox.Show(ex.Message,"打印设置出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
  30.             }
  31.             
  32.  
  33.         }
  34.  
  35.         private void button2_Click(object sender, EventArgs e)
  36.         {
  37.             if (printDialog1.ShowDialog() == DialogResult.OK)
  38.             {
  39.                 MessageBox.Show("打印");
  40.             }
  41.         }
  42.  
  43.         private void button4_Click(object sender, EventArgs e)
  44.         {
  45.             try
  46.             {
  47.                 printPreviewDialog1.Document = printDocument1;
  48.                 printPreviewDialog1.ShowDialog();
  49.             }
  50.             catch (Exception ex)
  51.             {
  52.                 MessageBox.Show(ex.Message,"打印预览出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
  53.                  
  54.             }
  55.              
  56.         }
  57.  
  58.         private void button3_Click(object sender, EventArgs e)
  59.         {
  60.             try
  61.             {
  62.                 printDocument1.Print();
  63.             }
  64.             catch (Exception ex)
  65.             {
  66.                 MessageBox.Show(ex.Message,"打印出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
  67.                  
  68.             }
  69.         }
  70.  
  71.         private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  72.         {
  73.             //左边距
  74.             int x = e.PageBounds.Left;
  75.             //上边距
  76.             int y = e.PageBounds.Top;
  77.             //获得绘图对象
  78.             Graphics g = e.Graphics;
  79.             Font printFont = new Font("宋体",14);
  80.             SolidBrush brush = new SolidBrush(Color.Black);
  81.             string text="第一次学习打印机设置,输出的文字内容";
  82.             g.DrawString(text,printFont,brush,x,y);
  83.         }
  84.     }
  85. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值