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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
C#打印原理解析及實(shí)例操作

C#打印原理其實(shí)就是生成MDI文件,那么什么是MDI文件呢?MDI是虛擬打印的文檔,系統(tǒng)碰到MDI的時(shí)候會(huì)自動(dòng)以打印的方式處理。所以,不管用什么模板,什么方式;能在PrintPage事件處理中,生成一張要打印內(nèi)容的圖片就OK了!

C#打印原理應(yīng)用實(shí)例:

 
 
 
  1. #region 打印  
  2.  
  3. private void btnPrint_Click(object sender, EventArgs e)  
  4.  
  5. {  
  6. //C#打印原理之打印預(yù)覽  
  7. //PrintPreviewDialog ppd = new PrintPreviewDialog();  
  8.  
  9. PrintDocument pd = new PrintDocument();  
  10.  
  11. //C#打印原理之設(shè)置邊距  
  12.  
  13. Margins margin = new Margins(20, 20, 20, 20);  
  14.  
  15. pd.DefaultPageSettings.Margins = margin;  
  16.  
  17. ////C#打印原理之紙張?jiān)O(shè)置默認(rèn)  
  18.  
  19. //PaperSize pageSize = new PaperSize("First custom size", 800, 600);  
  20.  
  21. //pd.DefaultPageSettings.PaperSize = pageSize;  
  22.  
  23. //C#打印原理之打印事件設(shè)置  
  24.  
  25. pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);  
  26.  
  27. //ppd.Document = pd;  
  28.  
  29. //ppd.ShowDialog();  
  30.  
  31. try 
  32.  
  33. {  
  34.  
  35. pd.Print();  
  36.  
  37. }  
  38.  
  39. catch (Exception ex)  
  40.  
  41. {  
  42.  
  43. MessageBox.Show(ex.Message, "打印出錯(cuò)",  
  44.  
  45.  MessageBoxButtons.OK, MessageBoxIcon.Error);  
  46.  
  47. pd.PrintController.OnEndPrint(pd, new PrintEventArgs());  
  48.  
  49. }  
  50.  
  51. }  
  52.  
  53. //C#打印原理之打印事件處理  
  54.  
  55. private void pd_PrintPage(object sender, PrintPageEventArgs e)  
  56.  
  57. {  
  58.  
  59. string date = lblDate.Text; //當(dāng)前日期  
  60.  
  61. string flowId = lblFlowId.Text; //流水號(hào)  
  62.  
  63. string payDate = PayDate.Year.ToString() + "年" +   
  64.  
  65. PayDate.Month.ToString() + "月"; //應(yīng)收年月  
  66.  
  67. string adminId = lblAdminId.Text;   //操作員編號(hào)  
  68.  
  69. string baseExpense = lblBaseExpense.Text; //應(yīng)交基本費(fèi)用  
  70.  
  71. string fine = lblFine.Text;   //罰款數(shù)目  
  72.  
  73. string upExpense = lblUpExpense.Text;   //上月上余  
  74.  
  75. string actualExpense = txtActualExpense.Text;   //實(shí)際應(yīng)交費(fèi)用  
  76.  
  77. string chineseExpense = DecimalToChinese.ConvertSum(actualExpense);    
  78.  //實(shí)際應(yīng)交費(fèi)用的中文大寫(xiě)  
  79.  
  80. //C#打印原理之讀取圖片模板  
  81.  
  82. Image temp = Image.FromFile(@"Receipts.jpg");  
  83.  
  84. GetResultIntoImage(ref temp, UserId, flowId, date, baseExpense,  
  85.  
  86.  fine, upExpense, actualExpense, chineseExpense, payDate, adminId);  
  87.  
  88. int x = e.MarginBounds.X;  
  89.  
  90. int y = e.MarginBounds.Y;  
  91.  
  92. int width = temp.Width;  
  93.  
  94. int height = temp.Height;  
  95.  
  96. Rectangle destRect = new Rectangle(x, y, width, height);  
  97.  
  98. e.Graphics.DrawImage(temp, destRect, 0, 0, temp.Width,  
  99.  
  100.  temp.Height, System.Drawing.GraphicsUnit.Pixel);  
  101.  
  102. }  
  103.  
  104. ///   
  105.  
  106. /// 將收費(fèi)結(jié)果填充到圖片模板  
  107. ///C#打印原理  
  108. ///   
  109.  
  110. private void GetResultIntoImage(  
  111.  
  112. ref Image temp,  
  113.  
  114. string userId,  
  115.  
  116. string flowId,  
  117.  
  118. string currentDate,  
  119.  
  120. string baseExpense, string actualExpense,  
  121.  
  122. string chineseExpense,  
  123.  
  124. string payDate,  
  125.  
  126. string adminName)  
  127.  
  128. {  
  129.  
  130. //C#打印原理之讀取圖片模板  
  131.  
  132. Graphics g = Graphics.FromImage(temp);  
  133.  
  134. Font f = new Font("宋體", 12);  
  135.  
  136. Brush b = new SolidBrush(Color.Black);  
  137.  
  138. //C#打印原理之填充數(shù)據(jù)到圖片模板(位置要在制作圖片模板的時(shí)候度量好)  
  139.  
  140. g.DrawImage(temp, 0, 0, temp.Width, temp.Height);  
  141.  
  142. g.DrawString(userId, f, b, 168, 105);  
  143.  
  144. g.DrawString(UserName, f, b, 166, 134);  
  145.  
  146. g.DrawString(flowId, f, b, 535, 105);  
  147.  
  148. g.DrawString(currentDate, f, b, 535, 134);  
  149.  
  150. g.DrawString(baseExpense, f, b, 219, 202);  
  151.  
  152. g.DrawString(fine, f, b, 372, 202);  
  153.  
  154. g.DrawString(upExpense, f, b, 486, 202);  
  155.  
  156. g.DrawString(actualExpense, f, b, 596, 202);  
  157.  
  158. g.DrawString(chineseExpense, f, b, 196, 238);  
  159.  
  160. g.DrawString(payDate, f, b, 176, 269);  
  161.  
  162. g.DrawString(adminName, f, b, 497, 298);  
  163.  
  164. g.Dispose();  
  165.  
  166. }  

C#打印原理的基本內(nèi)容以及實(shí)例的解析就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#打印原理有所幫助。

【編輯推薦】

  1. C#打印設(shè)置實(shí)例解析
  2. C#Lpt端口打印類(lèi)的操作淺析
  3. C#打印設(shè)置實(shí)現(xiàn)源碼詳解
  4. C#打印控件的使用實(shí)例淺析
  5. C#打印條碼操作的實(shí)例淺析

本文標(biāo)題:C#打印原理解析及實(shí)例操作
網(wǎng)頁(yè)URL:http://m.5511xx.com/article/dhcdojg.html