C#编程-136:Windows打印技术
2023-05-19 05:51:01 阅读次数:92
打印
using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
-
- namespace PrintDialogTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- pageSetupDialog1.Document = printDocument1;
- pageSetupDialog1.ShowDialog();
- }
- catch (Exception ex)
- {
-
- MessageBox.Show(ex.Message,"打印设置出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
- }
-
-
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- if (printDialog1.ShowDialog() == DialogResult.OK)
- {
- MessageBox.Show("打印");
- }
- }
-
- private void button4_Click(object sender, EventArgs e)
- {
- try
- {
- printPreviewDialog1.Document = printDocument1;
- printPreviewDialog1.ShowDialog();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message,"打印预览出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
-
- }
-
- }
-
- private void button3_Click(object sender, EventArgs e)
- {
- try
- {
- printDocument1.Print();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message,"打印出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
-
- }
- }
-
- private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
- {
- //左边距
- int x = e.PageBounds.Left;
- //上边距
- int y = e.PageBounds.Top;
- //获得绘图对象
- Graphics g = e.Graphics;
- Font printFont = new Font("宋体",14);
- SolidBrush brush = new SolidBrush(Color.Black);
- string text="第一次学习打印机设置,输出的文字内容";
- g.DrawString(text,printFont,brush,x,y);
- }
- }
- }
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/mouday/3048637,作者:彭世瑜,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。
上一篇:c#编程:
下一篇:踩坑之RedisTemplate执行Lua脚本