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

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
C#做ScreenCapture程序

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

成都創(chuàng)新互聯(lián)公司專注于新洲網站建設服務及定制,我們擁有豐富的企業(yè)做網站經驗。 熱誠為您提供新洲營銷型網站建設,新洲網站制作、新洲網頁設計、新洲網站官網定制、小程序設計服務,打造新洲網絡公司原創(chuàng)品牌,更為您提供新洲網站排名全網營銷落地服務。

在掌握了一些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 // 任意的打印機數(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. //由一個指定設備的句柄創(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. //把當前屏幕捕獲到位圖對象中  
  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. //關閉系統(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. //設定托盤程序的各個屬性  
  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 = "捕獲當前屏幕!" ;  
  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. //為托盤程序加入設定好的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程序


分享標題:C#做ScreenCapture程序
當前路徑:http://www.dlmjj.cn/article/djcjihi.html