日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
實(shí)現(xiàn)C#打印窗體實(shí)例詳解

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

創(chuàng)新互聯(lián)建站是一家專業(yè)提供湘東企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、H5頁(yè)面制作、小程序制作等業(yè)務(wù)。10年已為湘東眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。

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

◆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#打印窗體有所幫助。


分享題目:實(shí)現(xiàn)C#打印窗體實(shí)例詳解
當(dāng)前網(wǎng)址:http://www.dlmjj.cn/article/cdsdddc.html