C#打印设置是如何在实际编程开发中体现的呢?C#打印设置需要注意什么呢?C#打印设置常用属性是如何进行操作的呢?让我们在实例中解决这些问题吧:

C#打印设置实例代码:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication1
{/// <summary>  /// C#打印设置之Form1 的摘要说明。  /// </summary>  public class Form1 : System.Windows.Forms.Form{private System.Drawing.Printing.PrintDocument pd;private PrintPreviewControl ppc;private PrintPreviewDialog ppd;private System.Windows.Forms.PrintDialog printDialog1;private System.Windows.Forms.Button button1;private System.Windows.Forms.Button button2;private System.Windows.Forms.Button button3;private System.Windows.Forms.TextBox textBox1;String text = "";/// <summary>  /// C#打印设置之必需的设计器变量。  /// </summary>  private System.ComponentModel.Container components = null;public Form1(){//  // C#打印设置之Windows 窗体设计器支持所必需的  //  InitializeComponent();//  // TODO: 在 InitializeComponent 调用后添加任何构造函数代码  //  }/// <summary>  /// C#打印设置之清理所有正在使用的资源。  /// </summary>  protected override void Dispose(bool disposing){if (disposing){if (components != null){components.Dispose();}}base.Dispose(disposing);}#region Windows 窗体设计器生成的代码  /// <summary>  /// C#打印设置之设计器支持所需的方法 - 不要使用代码编辑器修改  /// 此方法的内容。  /// </summary>  private void InitializeComponent(){this.pd = new System.Drawing.Printing.PrintDocument();this.button1 = new System.Windows.Forms.Button();this.button2 = new System.Windows.Forms.Button();this.button3 = new System.Windows.Forms.Button();this.textBox1 = new System.Windows.Forms.TextBox();this.printDialog1 = new System.Windows.Forms.PrintDialog();this.SuspendLayout();//   // button1  //   this.button1.Location = new System.Drawing.Point(32, 154);this.button1.Name = "button1";this.button1.Size = new System.Drawing.Size(75, 23);this.button1.TabIndex = 1;this.button1.Text = "开始打印";this.button1.Click += new System.EventHandler(this.button1_Click);//   // button2  //   this.button2.Location = new System.Drawing.Point(120, 154);this.button2.Name = "button2";this.button2.Size = new System.Drawing.Size(75, 23);this.button2.TabIndex = 2;this.button2.Text = "打印预览";this.button2.Click += new System.EventHandler(this.button2_Click);//   // button3  //   this.button3.Location = new System.Drawing.Point(208, 154);this.button3.Name = "button3";this.button3.Size = new System.Drawing.Size(75, 23);this.button3.TabIndex = 3;this.button3.Text = "打印机设置";this.button3.Click += new System.EventHandler(this.button3_Click);//   // textBox1  //   this.textBox1.Location = new System.Drawing.Point(16, 16);this.textBox1.Multiline = true;this.textBox1.Name = "textBox1";this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;this.textBox1.Size = new System.Drawing.Size(270, 116);this.textBox1.TabIndex = 4;//   // Form1  //   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);this.ClientSize = new System.Drawing.Size(314, 199);this.Controls.Add(this.textBox1);this.Controls.Add(this.button3);this.Controls.Add(this.button2);this.Controls.Add(this.button1);this.Name = "Form1";this.Text = "打印窗体";this.Load += new System.EventHandler(this.Form1_Load);this.ResumeLayout(false);this.PerformLayout();}#endregion/// <summary>  /// C#打印设置之应用程序的主入口点。  /// </summary>  [STAThread]static void Main(){Application.Run(new Form1());}private void Form1_Load(object sender, System.EventArgs e){//C#打印设置之创建实例  this.pd = new System.Drawing.Printing.PrintDocument();this.ppc = new PrintPreviewControl();this.ppd = new PrintPreviewDialog();this.printDialog1 = new PrintDialog();//C#打印设置之触发事件  this.pd.BeginPrint += new System.Drawing.Printing.PrintEventHandler(pd_BeginPrint);this.pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);}private void pd_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e){//C#打印设置之设置横向打印  this.pd.DefaultPageSettings.Landscape = true;//C#打印设置之设置彩色打印  this.pd.DefaultPageSettings.Color = true;//C#打印设置之设置打印纸张类型和大小  this.pd.DefaultPageSettings.PaperSize =new System.Drawing.Printing.PaperSize("A4", 800, 1100);}private void pd_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e){//C#打印设置之获取文本框的内容绘制图形传到打印机打印  text = this.textBox1.Text;e.Graphics.DrawString(text,new Font("宋体", 30, FontStyle.Regular),Brushes.Black, 0, 0);}private void button1_Click(object sender,System.EventArgs e){//C#打印设置之开始打印  this.pd.Print();}private void button2_Click(object sender,System.EventArgs e){//C#打印设置之设置打印预览信息  ppc.Document = pd;ppc.Columns = 2;ppc.Rows = 2;ppc.Zoom = 0.5;ppc.StartPage = 1;//C#打印设置之显示预览  ppd.Document = pd;try{ppd.ShowDialog();}catch (Exception excep){MessageBox.Show(excep.Message,"打印出错", MessageBoxButtons.OK,MessageBoxIcon.Error);}}private void button3_Click(object sender,System.EventArgs e){//C#打印设置之打印机设置  this.printDialog1.Document = pd;this.printDialog1.AllowSomePages = true;this.printDialog1.PrintToFile = false;//C#打印设置之确定打印机信息后开始打印  if (this.printDialog1.ShowDialog() == DialogResult.OK){try{this.pd.Print();}catch (Exception excep){MessageBox.Show(excep.Message,"打印出错", MessageBoxButtons.OK,MessageBoxIcon.Error);}}}}
}

打印系统开发(25)——C#打印设置实现源码详解相关推荐

  1. Android AR开发实践之七:OpenGLES相机预览背景绘制源码详解

    Android AR开发实践之七:OpenGLES相机预览背景绘制源码详解 目录 Android AR开发实践之七:OpenGLES相机预览背景绘制源码详解 一.OpenGL ES渲染管线 1.基本处 ...

  2. freertos源码详解与应用开发 pdf_互联网企业面试必问Spring源码?搞定Spring源码,看完这篇就够了...

    不用说,Spring已经成为Java后端开发的事实上的行业标准.无数公司选择Spring作为基本开发框架.大多数Java后端程序员在日常工作中也会接触到Spring.因此,如何很好地使用Spring, ...

  3. 数字藏品系统开发,APP小程序成品源码搭建开发

    项目开发最重要的是追求质量,通过测试.在系统开发领域,很多项目有量无质,忽悠一些不知情的企业.NFT发展目前相当有名.我们可以做些什么来提高NFT发展的质量? 首先,找一家专业的NFT开发公司 作为一 ...

  4. 组件化开发之路由器模块详解(ActivityRouter源码详解)

    路由器的作用是什么?通俗的讲,路由器的作用就是一根网线满足多人上网的需求.而在开发中路由器模块的作用就是实现中转分发,也就是说将原来有关系的模块(有依赖的模块分开),产生一个中间的模块,让原来依赖的两 ...

  5. android 远程视频监控程序源码,详解基于Android已开放源代码的远程视频监控系统教程...

    网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket.Socket的英文原义是"孔"或"插座".通常也称作"套接字 ...

  6. MathEmatics11.3下开发第二讲之:加载wrl模型源码详解

    1 新建程序 进入界面,点击新建nb文件. 为自己的笔记本命名一个自己喜欢的名字. 2 源码 在文件中输入如下源码 Off[General::shdw, Unset::norep]; SetDirec ...

  7. 【C语言/C++】益智游戏开发:2048(源码详解)

    前言 C/C++作为元老级的编程语言,任时光更迭依旧屹立不倒,哪怕如今炙手可热的AI,其底层也是用其编写.C/C++可以说是永不过时的语言. 那么作为新手该如何上手这门语言?一切不敲代码的学编程手段都 ...

  8. 打印系统开发(23)——c# PrintDocument 设置自定义纸张大小的示例

    .Net 提供的打印类PrintDocument 非常简洁易用,不过在实际应用开发中往往需要对纸张进行自定义,尤其是需要进行票据打印时.这个问题也困扰了我许久,经过查阅相关的资料和多次尝试,发现其实也 ...

  9. nRF52832 bootloader DFU固件升级源码详解(结合RTT日志打印)

    文章目录 一.前文 二.init 三.nrf_dfu_command_req 四.dfu_handle_prevalidate 五.nrf_dfu_find_cache 六.nrf_dfu_data_ ...

最新文章

  1. colMedians(x) : Argument ‘x’ must be a matrix、rowMedians(data) : Argument ‘x‘ must be a matrix.
  2. java校验框架源码解析_Spring Boot原理剖析和源码分析
  3. valgrind 常见错误提示信息
  4. asp手机拍照显示_会员动态飞凯材料120吨TFTLCD混合液晶显示项目,建后五年达产...
  5. 64位内核开发第8讲,文件操作.以及删除文件.
  6. 人脸检测与对齐之MTCNN网络
  7. 如何避免重要需求遗漏?
  8. 本想制衡经销商价格,不料成为黄牛货源地!茅台电商公司被迫解散!
  9. ionic 性能优化
  10. python编程是啥-什么是少儿Python编程?这一篇就够啦!
  11. php序列化后换服务器不能解析,利用php序列化和反序列化的语法差异绕过防护_网站服务器运行维护...
  12. 丢失控制文件恢复实验记录--4(在线日志文件没有损坏,归档日志丢失,直接重建控制文件(跟踪控制文件trace是旧的情况))...
  13. spring boot实现邮箱验证码注册
  14. mc服务器资源包在什么文件夹,教程/制作资源包 _ 《我的世界》中文Minecraft Wiki:最详细的官方我的世界百科...
  15. Mac删除文件提示“不能删除xx项目,正在使用中”
  16. 字节的UTF-8 序列的字节无效的bug处理方案
  17. WIN10极限清理 C盘空间
  18. OpenBUGS、WinBUGS下载安装网址更新
  19. 将Raspberry Pi用作台式PC的17个最佳Raspbian应用
  20. 爬虫读取疫情数据,可根据兴趣进行调整,并邮件形式每天定时发送

热门文章

  1. [附源码]JAVA+ssm计算机毕业设计搬家预约系统(程序+Lw)
  2. 方舟如何管理linux服务器,方舟:生存进化CentOS开服教程
  3. 7000万台的背后,值得小米深思
  4. Mysql中7种日志
  5. Js完美验证15/18身份证
  6. 【杂项】任务管理器中的文件资源管理器不小心给结束任务了
  7. Python OpenCV 人脸识别
  8. ftp服务器显示不是私密登录,ftp服务器显示不是私密登录
  9. 钉钉小程序与微信小程序的异同
  10. 基于SpringBoot、MyBatis-plus实现双数据源定时同步