小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

實(shí)現(xiàn)C#打印窗體實(shí)例詳解

 偷心無(wú)痕 2013-12-11

如何在 Windows 下實(shí)現(xiàn)C#打印窗體作為C#開(kāi)發(fā)過(guò)程的一部分,通常會(huì)希望C#打印窗體的副本。下面的代碼示例演示如何使用 CopyFromScreen 方法來(lái)實(shí)現(xiàn)C#打印窗體的副本。

  1. using System;  
  2. using System.Windows.Forms;  
  3. using System.Drawing;  
  4. using System.Drawing.Printing;  
  5.  
  6. public class Form1 :  
  7.  Form  
  8. {//實(shí)現(xiàn)C#打印窗體  
  9. private Button printButton = new Button();  
  10. private PrintDocument printDocument1 = new PrintDocument();  
  11.  
  12. public Form1()  
  13.  {  
  14.  printButton.Text = "Print Form";  
  15.  printButton.Click += new EventHandler(printButton_Click);  
  16.  printDocument1.PrintPage +=   
  17. new PrintPageEventHandler(printDocument1_PrintPage);  
  18. this.Controls.Add(printButton);  
  19.  }  
  20.  
  21. void printButton_Click(object sender, EventArgs e)  
  22.  {  
  23.  CaptureScreen();  
  24.  printDocument1.Print();  
  25.  }  
  26. //實(shí)現(xiàn)C#打印窗體  
  27.  Bitmap memoryImage;  
  28.  
  29. private void CaptureScreen()  
  30.  {  
  31.  Graphics myGraphics = this.CreateGraphics();  
  32.  Size s = this.Size;  
  33.  memoryImage = new Bitmap(s.Width, s.Height, myGraphics);  
  34.  Graphics memoryGraphics = Graphics.FromImage(memoryImage);  
  35.  memoryGraphics.CopyFromScreen(  
  36. this.Location.X, this.Location.Y, 0, 0, s);  
  37.  }  
  38.  
  39. private void printDocument1_PrintPage(System.Object sender,     
  40. System.Drawing.Printing.PrintPageEventArgs e)  
  41.  {  
  42.  e.Graphics.DrawImage(memoryImage, 0, 0);  
  43.  }  
  44.  
  45.    //實(shí)現(xiàn)C#打印窗體  
  46.  
  47. public static void Main()  
  48.  {  
  49.  Application.Run(new Form1());  
  50.  }  
  51. }  

◆C#打印窗體之編譯代碼

這是一個(gè)完整的代碼示例,其中包含 Main 方法。

◆C#打印窗體之可靠編程

1、以下情況可能會(huì)導(dǎo)致異常:

2、您沒(méi)有訪問(wèn)該打印機(jī)的權(quán)限。

3、沒(méi)有安裝打印機(jī)。

◆C#打印窗體之安全

為了運(yùn)行此代碼示例,您必須能夠訪問(wèn)與計(jì)算機(jī)一起使用的打印機(jī)。

C#打印窗體的具體內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#打印窗體有所幫助。

【編輯推薦】

  1. C#入門(mén)之C#特點(diǎn)淺析
  2. .NET Framework概念及開(kāi)發(fā)淺析
  3. C#實(shí)現(xiàn)打印功能實(shí)例詳解
  4. 淺析C#打印和C#打印預(yù)覽的實(shí)現(xiàn)
  5. 全面解析C#實(shí)現(xiàn)打印功能
【責(zé)任編輯:李彥光 TEL:(010)68476606】

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多