日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#打印設(shè)置實現(xiàn)源碼詳解

C#打印設(shè)置是如何在實際編程開發(fā)中體現(xiàn)的呢?C#打印設(shè)置需要注意什么呢?C#打印設(shè)置常用屬性是如何進行操作的呢?讓我們在實例中解決這些問題吧:

創(chuàng)新互聯(lián)建站是專業(yè)的文成網(wǎng)站建設(shè)公司,文成接單;提供成都網(wǎng)站建設(shè)、成都網(wǎng)站制作,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行文成網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

C#打印設(shè)置實例代碼:

 
 
 
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. namespace WindowsApplication1
  8. {
  9.  /// 
  10.  /// C#打印設(shè)置之Form1 的摘要說明。
  11.  /// 
  12.  public class Form1 : System.Windows.Forms.Form
  13.  {
  14. private System.Drawing.Printing.PrintDocument pd;
  15. private PrintPreviewControl ppc;
  16. private PrintPreviewDialog ppd;
  17. private System.Windows.Forms.PrintDialog printDialog1;
  18. private System.Windows.Forms.Button button1;
  19. private System.Windows.Forms.Button button2;
  20. private System.Windows.Forms.Button button3;
  21. private System.Windows.Forms.TextBox textBox1;
  22. String text="";
  23. /// 
  24. /// C#打印設(shè)置之必需的設(shè)計器變量。
  25. /// 
  26. private System.ComponentModel.Container components = null;
  27. public Form1()
  28. {
  29.  //
  30.  // C#打印設(shè)置之Windows 窗體設(shè)計器支持所必需的
  31.  //
  32.  InitializeComponent();
  33.  //
  34.  // TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
  35.  //
  36. }
  37. /// 
  38. /// C#打印設(shè)置之清理所有正在使用的資源。
  39. /// 
  40. protected override void Dispose( bool disposing )
  41. {
  42.  if( disposing )
  43.  {
  44. if (components != null) 
  45. {
  46.  components.Dispose();
  47. }
  48.  }
  49.  base.Dispose( disposing );
  50. }
  51. #region Windows 窗體設(shè)計器生成的代碼
  52. /// 
  53. /// C#打印設(shè)置之設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
  54. /// 此方法的內(nèi)容。
  55. /// 
  56. private void InitializeComponent()
  57. {
  58. this.pd = new System.Drawing.Printing.PrintDocument();
  59. this.button1 = new System.Windows.Forms.Button();
  60. this.button2 = new System.Windows.Forms.Button();
  61. this.button3 = new System.Windows.Forms.Button();
  62. this.textBox1 = new System.Windows.Forms.TextBox();
  63. this.printDialog1 = new System.Windows.Forms.PrintDialog();
  64. this.SuspendLayout();
  65. // 
  66. // button1
  67. // 
  68. this.button1.Location = new System.Drawing.Point(32, 154);
  69. this.button1.Name = "button1";
  70. this.button1.Size = new System.Drawing.Size(75, 23);
  71. this.button1.TabIndex = 1;
  72. this.button1.Text = "開始打印";
  73. this.button1.Click += new System.EventHandler(this.button1_Click);
  74. // 
  75. // button2
  76. // 
  77. this.button2.Location = new System.Drawing.Point(120, 154);
  78. this.button2.Name = "button2";
  79. this.button2.Size = new System.Drawing.Size(75, 23);
  80. this.button2.TabIndex = 2;
  81. this.button2.Text = "打印預(yù)覽";
  82. this.button2.Click += new System.EventHandler(this.button2_Click);
  83. // 
  84. // button3
  85. // 
  86. this.button3.Location = new System.Drawing.Point(208, 154);
  87. this.button3.Name = "button3";
  88. this.button3.Size = new System.Drawing.Size(75, 23);
  89. this.button3.TabIndex = 3;
  90. this.button3.Text = "打印機設(shè)置";
  91. this.button3.Click += new System.EventHandler(this.button3_Click);
  92. // 
  93. // textBox1
  94. // 
  95. this.textBox1.Location = new System.Drawing.Point(16, 16);
  96. this.textBox1.Multiline = true;
  97. this.textBox1.Name = "textBox1";
  98. this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
  99. this.textBox1.Size = new System.Drawing.Size(270, 116);
  100. this.textBox1.TabIndex = 4;
  101. // 
  102. // Form1
  103. // 
  104. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  105. this.ClientSize = new System.Drawing.Size(314, 199);
  106. this.Controls.Add(this.textBox1);
  107. this.Controls.Add(this.button3);
  108. this.Controls.Add(this.button2);
  109. this.Controls.Add(this.button1);
  110. this.Name = "Form1";
  111. this.Text = "打印窗體";
  112. this.Load += new System.EventHandler(this.Form1_Load);
  113. this.ResumeLayout(false);
  114. this.PerformLayout();
  115. }
  116. #endregion
  117. /// 
  118. /// C#打印設(shè)置之應(yīng)用程序的主入口點。
  119. /// 
  120. [STAThread]
  121. static void Main() 
  122. {
  123.  Application.Run(new Form1());
  124. }
  125. private void Form1_Load(object sender, System.EventArgs e)
  126. {
  127.  //C#打印設(shè)置之創(chuàng)建實例
  128.  this.pd=new System.Drawing.Printing.PrintDocument();
  129.  this.ppc=new PrintPreviewControl();
  130.  this.ppd=new PrintPreviewDialog();
  131.  this.printDialog1=new PrintDialog();
  132.  //C#打印設(shè)置之觸發(fā)事件
  133.  this.pd.BeginPrint+=new System.Drawing.Printing.PrintEventHandler(pd_BeginPrint);
  134.  this.pd.PrintPage+=new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);
  135.  
  136. }
  137. private void pd_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
  138.  //C#打印設(shè)置之設(shè)置橫向打印
  139.  this.pd.DefaultPageSettings.Landscape=true;
  140.  //C#打印設(shè)置之設(shè)置彩色打印
  141.  this.pd.DefaultPageSettings.Color=true;
  142.  //C#打印設(shè)置之設(shè)置打印紙張類型和大小
  143.  this.pd.DefaultPageSettings.PaperSize=
  144. new System.Drawing.Printing.PaperSize("A4",800,1100);
  145. }
  146. private void pd_PrintPage(object sender, 
  147. System.Drawing.Printing.PrintPageEventArgs e)
  148. {
  149.  //C#打印設(shè)置之獲取文本框的內(nèi)容繪制圖形傳到打印機打印
  150.  text=this.textBox1.Text;
  151.  e.Graphics.DrawString(text, 
  152. new Font("宋體",30, FontStyle.Regular), 
  153. Brushes.Black, 0, 0);
  154.  
  155. }
  156. private void button1_Click(object sender, 
  157. System.EventArgs e)
  158. {
  159.  //C#打印設(shè)置之開始打印
  160. this.pd.Print();
  161.  
  162. }
  163. private void button2_Click(object sender, 
  164. System.EventArgs e)
  165. {
  166.  //C#打印設(shè)置之設(shè)置打印預(yù)覽信息
  167.  ppc.Document=pd;
  168.  ppc.Columns=2;
  169.  ppc.Rows=2;
  170.  ppc.Zoom=0.5;
  171.  ppc.StartPage=1;
  172.  
  173.  //C#打印設(shè)置之顯示預(yù)覽
  174.  ppd.Document=pd;
  175. try
  176. {
  177. ppd.ShowDialog();
  178. }
  179. catch (Exception excep)
  180. {
  181. MessageBox.Show(excep.Message, 
  182. "打印出錯", MessageBoxButtons.OK, 
  183. MessageBoxIcon.Error);
  184. }
  185.  
  186. }
  187. private void button3_Click(object sender, 
  188. System.EventArgs e)
  189. {
  190.  //C#打印設(shè)置之打印機設(shè)置
  191.  this.printDialog1.Document=pd;
  192.  this.printDialog1.AllowSomePages=true;
  193.  this.printDialog1.PrintToFile=false;
  194.  //C#打印設(shè)置之確定打印機信息后開始打印
  195.  if(this.printDialog1.ShowDialog()==DialogResult.OK)
  196.  {
  197. try
  198. {
  199. this.pd.Print();
  200. }
  201. catch (Exception excep)
  202. {
  203. MessageBox.Show(excep.Message, 
  204. "打印出錯", MessageBoxButtons.OK,
  205.  MessageBoxIcon.Error); 
  206. }
  207.  }
  208. }
  209.  }
  210. }

C#打印設(shè)置的相關(guān)實例以及介紹就向你講述到這里,很多具體的操作都在注釋中體現(xiàn),希望對你了解和學(xué)習(xí)C#打印設(shè)置有所幫助。


網(wǎng)站欄目:C#打印設(shè)置實現(xiàn)源碼詳解
URL標(biāo)題:http://m.5511xx.com/article/cdijjes.html