成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

C#做Screen Capture程序

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

用C#做Screen Capture程序的代碼和運行節目:

在掌握了一些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. //導入在程序中使用到的名稱空間  
  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 , //目標設備的句柄  
  29. int nXDest , // 目標對象的左上角的X坐標  
  30. int nYDest , // 目標對象的左上角的X坐標  
  31. int nWidth , // 目標對象的矩形的寬度  
  32. int nHeight , // 目標對象的矩形的長度  
  33. IntPtr hdcSrc , // 源設備的句柄  
  34. int nXSrc , // 源對象的左上角的X坐標  
  35. int nYSrc , // 源對象的左上角的X坐標  
  36. System.Int32 dwRop // 光柵的操作值  
  37. ) ;  
  38. [ System.Runtime.InteropServices.DllImportAttribute ( "gdi32.dll" ) ]  
  39. private static extern IntPtr CreateDC (  
  40. string lpszDriver , // 驅動名稱  
  41. string lpszDevice , // 設備名稱  
  42. string lpszOutput , // 無用,可以設定位"NULL"  
  43. IntPtr lpInitData // 任意的打印機數據  
  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. //創建顯示器的DC  
  50. Graphics g1 = Graphics.FromHdc ( dc1 ) ;  
  51. //由一個指定設備的句柄創建一個新的Graphics對象  
  52. MyImage = new Bitmap ( Screen.PrimaryScreen.Bounds.Width , 
    Screen.PrimaryScreen.Bounds.Height , g1 ) ;  
  53. //根據屏幕大小創建一個與之相同大小的Bitmap對象  
  54. Graphics g2 = Graphics.FromImage ( MyImage ) ;  
  55. //獲得屏幕的句柄  
  56. IntPtr dc3 = g1.GetHdc ( ) ;  
  57. //獲得位圖的句柄  
  58. IntPtr dc2 = g2.GetHdc ( ) ;  
  59. //把當前屏幕捕獲到位圖對象中  
  60. BitBlt ( dc2 , 0 , 0 , Screen.PrimaryScreen.Bounds.Width , 
    Screen.PrimaryScreen.Bounds.Height , dc3 , 0 , 0 , 13369376 ) ;  
  61. //把當前屏幕拷貝到位圖中  
  62. g1.ReleaseHdc ( dc3 ) ;  
  63. //釋放屏幕句柄  
  64. g2.ReleaseHdc ( dc2 ) ;  
  65. //釋放位圖句柄  
  66. MyImage.Save ( "c:\\MyJpeg.jpg" , ImageFormat.Jpeg ) ;  
  67. MessageBox.Show ( "已經把當前屏幕保存到C:\\MyJpeg.jpg文件中!" ) ;  
  68. this.Visible = true ;  
  69. }  
  70. public void ExitSelect ( object sender , System.EventArgs e )  
  71. {  
  72. //隱藏托盤程序中的圖標  
  73. TrayIcon.Visible = false ;  
  74. //關閉系統  
  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. //設定托盤程序的各個屬性  
  87. TrayIcon = new NotifyIcon ( ) ;  
  88. TrayIcon.Icon = mNetTrayIcon ;  
  89. TrayIcon.Text = "用C#做Screen Capture程序" ;  
  90. TrayIcon.Visible = true ;  
  91. //定義一個MenuItem數組,并把此數組同時賦值給ContextMenu對象  
  92. MenuItem [ ] mnuItms = new MenuItem [ 3 ] ;  
  93. mnuItms [ 0 ] = new MenuItem ( ) ;  
  94. mnuItms [ 0 ] .Text = "捕獲當前屏幕!" ;  
  95. mnuItms [ 0 ] .Click += new System.EventHandler ( this.capture ) ;  
  96. mnuItms [ 1 ] = new MenuItem ( "-" ) ;  
  97. mnuItms [ 2 ] = new MenuItem ( ) ;  
  98. mnuItms [ 2 ] .Text = "退出系統" ;  
  99. mnuItms [ 2 ] .Click += new System.EventHandler ( this.ExitSelect ) ;  
  100. mnuItms [ 2 ] .DefaultItem = true ;  
  101. notifyiconMnu = new ContextMenu ( mnuItms ) ;  
  102. TrayIcon.ContextMenu = notifyiconMnu ;  
  103. //為托盤程序加入設定好的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#實現PrintPage方法
  3. 利用Visual C#和C#語言特性
  4. C#管道技術學習經驗
  5. 概述C#復合控件構建
責任編輯:佚名 來源: 博客園
相關推薦

2009-08-20 10:54:29

C#做瀏覽器源程序

2009-08-20 16:02:15

C#正則表達式

2009-08-13 17:04:09

C#語言C#程序

2009-08-19 17:11:49

C#程序集

2009-08-20 17:49:53

學習C#程序

2009-08-07 17:32:17

C#編譯程序

2009-08-12 17:44:30

C# Web Serv

2009-08-12 18:28:09

C#事件處理程序

2009-08-24 15:46:46

C# SmartPho

2009-08-13 17:15:44

C#屏幕保護程序

2009-08-26 15:10:34

脫離.net fram

2009-08-24 14:19:27

C# Windows應

2009-08-24 09:25:18

Visual C# ..NET應用程序

2009-08-11 13:48:11

C# ConfigDl

2009-08-14 11:00:16

C#創建Windows

2009-08-28 16:03:15

C#程序實現鼠標移動

2009-08-25 17:24:55

C#串口通信程序

2009-08-06 10:27:08

C#應用程序域

2009-08-12 18:20:39

C#事件驅動程序

2011-04-08 09:52:44

C++C#DLL
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 一级片毛片 | www,黄色,com | 亚洲精品一区av在线播放 | 妞干网视频 | 综合久久久久 | 在线视频中文字幕 | 亚洲精品观看 | 久久这里只有精品首页 | 精品久久久久久 | 久久五月婷 | 日韩欧美精品一区 | 日韩电影中文字幕在线观看 | 中文字幕一区在线 | 亚洲一区二区在线 | 中文字幕在线视频精品 | 精品福利在线视频 | 午夜激情影院 | 天天看天天摸天天操 | 成人一区二区三区在线 | 亚洲高清一区二区三区 | 日韩国产中文字幕 | 日韩福利在线 | 亚洲www | 欧美 日本 国产 | 日韩中文在线视频 | 精久久久 | 亚洲成人一区 | 国产精品一二三区 | 99精品在线| 亚洲欧洲小视频 | 亚洲国产看片 | 中文字幕电影在线观看 | 一区二区高清 | 色综合天天综合网国产成人网 | 一区二区三区国产视频 | 亚洲成人综合在线 | 麻豆视频国产在线观看 | 亚洲久久一区 | 国产精品一区二区欧美 | 99爱国产| 一区在线播放 |