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

C#做Screen Capture程序

開發(fā) 后端
這里介紹C#做Screen Capture程序,在掌握了一些C#源代碼后,可以得到用C#做Screen Capture程序的源代碼具體如下。

用C#做Screen Capture程序的代碼和運(yùn)行節(jié)目:

在掌握了一些C#源代碼后,可以得到用C#做Screen Capture程序的源代碼(Capture.cs),具體如下:

  1. using System ;  
  2. using System.Drawing ;  
  3. using System.Collections ;  
  4. using System.ComponentModel ;  
  5. using System.Windows.Forms ;  
  6. using System.Data ;  
  7. using System.Drawing.Imaging ;  
  8. using System.IO ;  
  9. //導(dǎo)入在程序中使用到的名稱空間  
  10. public class Capture : Form  
  11. {  
  12. private System.ComponentModel.Container components = null ;  
  13. private Icon mNetTrayIcon = new Icon ( "Tray.ico" ) ;  
  14. private Bitmap MyImage = null ;  
  15. private NotifyIcon TrayIcon ;  
  16. private ContextMenu notifyiconMnu ;  
  17. public Capture ( )  
  18. {  
  19. //初始化窗體中使用到的組件  
  20. InitializeComponent ( ) ;  
  21. }  
  22. protected override void OnActivated ( EventArgs e )  
  23. {  
  24. this.Hide ( ) ;  
  25. }  
  26. [ System.Runtime.InteropServices.DllImportAttribute ( "gdi32.dll" ) ]  
  27. private static extern bool BitBlt (  
  28. IntPtr hdcDest , //目標(biāo)設(shè)備的句柄  
  29. int nXDest , // 目標(biāo)對象的左上角的X坐標(biāo)  
  30. int nYDest , // 目標(biāo)對象的左上角的X坐標(biāo)  
  31. int nWidth , // 目標(biāo)對象的矩形的寬度  
  32. int nHeight , // 目標(biāo)對象的矩形的長度  
  33. IntPtr hdcSrc , // 源設(shè)備的句柄  
  34. int nXSrc , // 源對象的左上角的X坐標(biāo)  
  35. int nYSrc , // 源對象的左上角的X坐標(biāo)  
  36. System.Int32 dwRop // 光柵的操作值  
  37. ) ;  
  38. [ System.Runtime.InteropServices.DllImportAttribute ( "gdi32.dll" ) ]  
  39. private static extern IntPtr CreateDC (  
  40. string lpszDriver , // 驅(qū)動名稱  
  41. string lpszDevice , // 設(shè)備名稱  
  42. string lpszOutput , // 無用,可以設(shè)定位"NULL"  
  43. IntPtr lpInitData // 任意的打印機(jī)數(shù)據(jù)  
  44. ) ;  
  45. public void capture ( object sender , System.EventArgs e )  
  46. {  
  47. this.Visible = false ;  
  48. IntPtr dc1 = CreateDC ( "DISPLAY" , null , null , ( IntPtr ) null ) ;  
  49. //創(chuàng)建顯示器的DC  
  50. Graphics g1 = Graphics.FromHdc ( dc1 ) ;  
  51. //由一個指定設(shè)備的句柄創(chuàng)建一個新的Graphics對象  
  52. MyImage = new Bitmap ( Screen.PrimaryScreen.Bounds.Width , 
    Screen.PrimaryScreen.Bounds.Height , g1 ) ;  
  53. //根據(jù)屏幕大小創(chuàng)建一個與之相同大小的Bitmap對象  
  54. Graphics g2 = Graphics.FromImage ( MyImage ) ;  
  55. //獲得屏幕的句柄  
  56. IntPtr dc3 = g1.GetHdc ( ) ;  
  57. //獲得位圖的句柄  
  58. IntPtr dc2 = g2.GetHdc ( ) ;  
  59. //把當(dāng)前屏幕捕獲到位圖對象中  
  60. BitBlt ( dc2 , 0 , 0 , Screen.PrimaryScreen.Bounds.Width , 
    Screen.PrimaryScreen.Bounds.Height , dc3 , 0 , 0 , 13369376 ) ;  
  61. //把當(dāng)前屏幕拷貝到位圖中  
  62. g1.ReleaseHdc ( dc3 ) ;  
  63. //釋放屏幕句柄  
  64. g2.ReleaseHdc ( dc2 ) ;  
  65. //釋放位圖句柄  
  66. MyImage.Save ( "c:\\MyJpeg.jpg" , ImageFormat.Jpeg ) ;  
  67. MessageBox.Show ( "已經(jīng)把當(dāng)前屏幕保存到C:\\MyJpeg.jpg文件中!" ) ;  
  68. this.Visible = true ;  
  69. }  
  70. public void ExitSelect ( object sender , System.EventArgs e )  
  71. {  
  72. //隱藏托盤程序中的圖標(biāo)  
  73. TrayIcon.Visible = false ;  
  74. //關(guān)閉系統(tǒng)  
  75. this.Close ( ) ;  
  76. }  
  77. //清除程序中使用過的資源  
  78. public override void Dispose ( )  
  79. {  
  80. base.Dispose ( ) ;  
  81. if ( components != null )  
  82. components.Dispose ( ) ;  
  83. }  
  84. private void InitializeComponent ( )  
  85. {  
  86. //設(shè)定托盤程序的各個屬性  
  87. TrayIcon = new NotifyIcon ( ) ;  
  88. TrayIcon.Icon = mNetTrayIcon ;  
  89. TrayIcon.Text = "用C#做Screen Capture程序" ;  
  90. TrayIcon.Visible = true ;  
  91. //定義一個MenuItem數(shù)組,并把此數(shù)組同時賦值給ContextMenu對象  
  92. MenuItem [ ] mnuItms = new MenuItem [ 3 ] ;  
  93. mnuItms [ 0 ] = new MenuItem ( ) ;  
  94. mnuItms [ 0 ] .Text = "捕獲當(dāng)前屏幕!" ;  
  95. mnuItms [ 0 ] .Click += new System.EventHandler ( this.capture ) ;  
  96. mnuItms [ 1 ] = new MenuItem ( "-" ) ;  
  97. mnuItms [ 2 ] = new MenuItem ( ) ;  
  98. mnuItms [ 2 ] .Text = "退出系統(tǒng)" ;  
  99. mnuItms [ 2 ] .Click += new System.EventHandler ( this.ExitSelect ) ;  
  100. mnuItms [ 2 ] .DefaultItem = true ;  
  101. notifyiconMnu = new ContextMenu ( mnuItms ) ;  
  102. TrayIcon.ContextMenu = notifyiconMnu ;  
  103. //為托盤程序加入設(shè)定好的ContextMenu對象  
  104. this.SuspendLayout ( ) ;  
  105. this.AutoScaleBaseSize = new System.Drawing.Size ( 5 , 13 ) ;  
  106. this.ClientSize = new System.Drawing.Size ( 320 , 56 ) ;  
  107. this.ControlBox = false ;  
  108. this.MaximizeBox = false ;  
  109. this.MinimizeBox = false ;  
  110. this.WindowState = System.Windows.Forms.FormWindowState.Minimized ;  
  111. this.Name = "capture" ;  
  112. this.ShowInTaskbar = false ;  
  113. this.Text = "用C#做Screen Capture程序!" ;  
  114. this.ResumeLayout ( false ) ;  
  115. }  
  116. static void Main ( )  
  117. {  
  118. Application.Run ( new Capture ( ) ) ;  
  119. }  
  120. }  

以上介紹C#做Screen Capture程序

【編輯推薦】

  1. 淺談C# Connection對象
  2. C#實現(xiàn)PrintPage方法
  3. 利用Visual C#和C#語言特性
  4. C#管道技術(shù)學(xué)習(xí)經(jīng)驗
  5. 概述C#復(fù)合控件構(gòu)建
責(zé)任編輯:佚名 來源: 博客園
相關(guān)推薦

2009-08-20 10:54:29

C#做瀏覽器源程序

2009-08-20 16:02:15

C#正則表達(dá)式

2009-08-13 17:04:09

C#語言C#程序

2009-08-19 17:11:49

C#程序集

2009-08-20 17:49:53

學(xué)習(xí)C#程序

2009-08-07 17:32:17

C#編譯程序

2009-08-12 18:28:09

C#事件處理程序

2009-08-12 17:44:30

C# Web Serv

2009-08-13 17:15:44

C#屏幕保護(hù)程序

2009-08-24 15:46:46

C# SmartPho

2009-08-26 15:10:34

脫離.net fram

2009-08-06 10:27:08

C#應(yīng)用程序域

2009-08-24 09:25:18

Visual C# ..NET應(yīng)用程序

2009-08-24 14:19:27

C# Windows應(yīng)

2009-08-28 16:03:15

C#程序?qū)崿F(xiàn)鼠標(biāo)移動

2009-08-14 11:00:16

C#創(chuàng)建Windows

2009-08-25 17:24:55

C#串口通信程序

2009-08-11 13:48:11

C# ConfigDl

2009-08-12 18:20:39

C#事件驅(qū)動程序

2011-04-08 09:52:44

C++C#DLL
點(diǎn)贊
收藏

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