如何进行C#打印设置实现源码的分析

技术如何进行C#打印设置实现源码的分析本篇文章为大家展示了如何进行C#打印设置实现源码的分析,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。C#打印设置是如何在实际编程开发中体现的

本篇文章为大家展示了如何进行C#打印设置实现源码的分析,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

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

C#打印设置实例代码:

使用系统;使用系统.绘图;使用系统.收藏品;使用系统.组件模型使用系统.窗户。窗体;使用系统.数据;命名空间windows应用程序1 {///summary///c#打印设置之表格一的摘要说明////summarypublicclassform 1:系统.窗户。表格。形成{私有系统.绘图。打印。打印文档PD;privatedprintpreviewcontrolppc;privatedprintpreviewdialogppd私有系统窗户。表格。printdialogprintdialog1私有系统窗户。表格。按钮按钮1;私有系统窗户。表格。按钮按钮2;私有系统窗户。表格。按钮按钮3;私有系统窗户。表格。文本框文本框1;Stringtext=///摘要///C#打印设置之必需的设计器变量////summaryprivateSystem。组件模型。容器组件=空;publicForm1(){////C#打印设置之Windows操作系统操作系统窗体设计器支持所必需的//初始化组件();////TODO:在InitializeComponent调用后添加任何构造函数代码//}///summary///C#打印设置之清理所有正在使用的资源////summaryprotectedovirdevodispose(booldisposing){ if(disposing){ if(components!=null){ 0组件dispose();} }基础。处置}nbs .

p; #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);   }   }  }   }  }

C#打印设置的相关实例以及介绍就向你讲述到这里,很多具体的操作都在注释中体现,希望对你了解和学习C#打印设置有所帮助。

上述内容就是如何进行C#打印设置实现源码的分析,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/113752.html

(0)

相关推荐

  • 窗口事件

    技术窗口事件 窗口事件1.窗口事件属性:
    window.onfocus = function(){ // 窗口获取焦点事件};
    window.οnblur= function(){ // 窗口失去焦点事

    礼包 2021年12月5日
  • 稳压二极管工作原理,稳压二极管的工作原理是什么

    技术稳压二极管工作原理,稳压二极管的工作原理是什么稳压管的工作原理:稳压管也是一种晶体二极管,它是利用PN结的击穿区具有稳定电压的特性来工作的。稳压管在稳压设备和一些电子电路中获得广泛的应用。把这种类型的二极管称为稳压管

    生活 2021年10月24日
  • className用法

    技术className用法 className用法className用法4.className用法例 4.1(keyIEFF.html)!DOCTYPE html PUBLIC "-//W3C//DTD

    礼包 2021年11月26日
  • 基于App SDK和API搭建无人自习室等无人场景有哪些

    技术基于App SDK和API搭建无人自习室等无人场景有哪些本篇文章给大家分享的是有关基于App SDK和API搭建无人自习室等无人场景有哪些,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,

    攻略 2021年12月10日
  • Solr4.7如何实现智能提示

    技术solr4.7智能提示怎么实现这篇文章主要介绍“solr4.7智能提示怎么实现”,在日常操作中,相信很多人在solr4.7智能提示怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”

    攻略 2021年12月22日
  • 中的偏旁,汉字中有几个部首

    技术中的偏旁,汉字中有几个部首《康熙字典》的部首限制在214个中的偏旁,为求搜寻的方便,有些部首的归类与字义无关。例如按照原则,所有象形字都应该自成部首,但这样会造成很多象形文字的部首只有这个字。所以像是“甲”“申”“由

    生活 2021年10月22日