自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

開發(fā) 后端
實(shí)現(xiàn)C#打印窗體實(shí)例向你詳細(xì)介紹了在 Windows 下實(shí)現(xiàn)C#打印窗體的具體步驟和實(shí)現(xiàn)實(shí)例演示。希望對(duì)你學(xué)習(xí)C#打印窗體有所幫助。

如何在 Windows 下實(shí)現(xiàn)C#打印窗體作為C#開發(fā)過程的一部分,通常會(huì)希望C#打印窗體的副本。下面的代碼示例演示如何使用 CopyFromScreen 方法來實(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、您沒有訪問該打印機(jī)的權(quán)限。

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

◆C#打印窗體之安全

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

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

【編輯推薦】

  1. C#入門之C#特點(diǎn)淺析
  2. .NET Framework概念及開發(fā)淺析
  3. C#實(shí)現(xiàn)打印功能實(shí)例詳解
  4. 淺析C#打印和C#打印預(yù)覽的實(shí)現(xiàn)
  5. 全面解析C#實(shí)現(xiàn)打印功能
責(zé)任編輯:仲衡 來源: 百度空間
相關(guān)推薦

2009-08-26 09:22:44

C#實(shí)現(xiàn)打印功能

2009-08-26 11:32:37

C#打印文檔

2009-09-07 06:18:57

C#窗體設(shè)計(jì)器

2009-09-07 03:44:50

C#窗體間傳值

2009-09-07 06:31:32

C#窗體移動(dòng)

2009-09-07 06:48:13

C#透明窗體

2009-08-26 12:59:08

C#打印設(shè)置

2009-08-21 10:13:02

C#異步初步

2009-08-26 11:53:56

C#打印文本文件

2009-09-07 05:10:52

C#模式窗體

2009-09-09 12:55:59

C# TextBox事

2009-08-26 12:14:44

C#打印設(shè)置

2009-09-01 18:06:06

c#保存窗體狀態(tài)

2009-08-25 09:19:01

C#實(shí)現(xiàn)窗體顯示

2009-09-02 17:12:06

C#關(guān)機(jī)代碼

2009-08-20 11:01:51

C#操作內(nèi)存

2009-09-11 12:31:52

C#實(shí)例詳解TypeConvert

2009-08-18 10:14:19

C#插件構(gòu)架

2009-08-26 09:54:45

C#打印預(yù)覽C#打印

2009-04-28 16:18:29

.Net MicroSideShow
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)