C#编程-136:Windows打印技术_彭世瑜_新浪博客
【摘要】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using S...
- 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);
- }
- }
- }
文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/109661904
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)