乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

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

       偷心無痕 2013-12-11

      如何在 Windows 下實現(xiàn)C#打印窗體作為C#開發(fā)過程的一部分,通常會希望C#打印窗體的副本。下面的代碼示例演示如何使用 CopyFromScreen 方法來實現(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. {//實現(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. //實現(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.    //實現(xiàn)C#打印窗體  
      46.  
      47. public static void Main()  
      48.  {  
      49.  Application.Run(new Form1());  
      50.  }  
      51. }  

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

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

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

      1、以下情況可能會導致異常:

      2、您沒有訪問該打印機的權限。

      3、沒有安裝打印機。

      ◆C#打印窗體之安全

      為了運行此代碼示例,您必須能夠訪問與計算機一起使用的打印機。

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

      【編輯推薦】

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

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

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多