日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

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

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

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

在掌握了一些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程序


當(dāng)前名稱:C#做ScreenCapture程序
網(wǎng)站URL:http://www.5511xx.com/article/djcjihi.html