, Screen.PrimaryScreen.Bounds.Width , Screen.PrimaryScreen.Bounds.Height , dc3 , 0 , 0 , 13369376 ) ;
//把当前屏幕拷贝到位图中
g1.ReleaseHdc ( dc3 ) ;
//释放屏幕句柄
g2.ReleaseHdc ( dc2 ) ;
//释放位图句柄
MyImage.Save ( "c:\\MyJpeg.jpg" , ImageFormat.Jpeg ) ;
MessageBox.Show ( "已经把当前屏幕保存到C:\\MyJpeg.jpg文件中!" ) ;
this.Visible = true ;
}
public void ExitSelect ( object sender , System.EventArgs e )
{
//隐藏托盘
程序中的图标
TrayIcon.Visible = false ;
//关闭系统
this.Close ( ) ;
}
//清除
程序中使用过的资源
public override void Dispose ( )
{
base.Dispose ( ) ;
if ( components != null )
components.Dispose ( ) ;
}
private void InitializeComponent ( )
{
//设定托盘程序的各个属性
TrayIcon = new NotifyIcon ( ) ;
TrayIcon.Icon = mNetTrayIcon ;
TrayIcon.Text = "用C#做Screen Capture程序" ;
TrayIcon.Visible = true ;
//定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
MenuItem [ ] mnuItms = new MenuItem [ 3 ] ;
mnuItms [ 0 ] = new MenuItem ( ) ;
mnuItms [ 0 ] .Text = "捕获当前屏幕!" ;
mnuItms [ 0 ] .Click += new System.EventHandler ( this.capture ) ;
mnuItms [ 1 ] = new MenuItem ( "-" ) ;
mnuItms [ 2 ] = new MenuItem ( ) ;
mnuItms [ 2 ] .Text = "退出系统" ;
mnuItms [ 2 ] .Click += new System.EventHandler ( this.ExitSelect ) ;
mnuItms [ 2 ] .DefaultItem = true ;
notifyiconMnu = new ContextMenu ( mnuItms ) ;
TrayIcon.ContextMenu = notifyiconMnu ;
//为托盘程序加入设定好的ContextMenu对象
this.SuspendLayout ( ) ;
this.AutoScaleBaseSize = new System.Drawing.Size ( 5 , 13 ) ;
this.ClientSize = new System.Drawing.Size ( 320 , 56 ) ;
this.ControlBox = false ;
this.MaximizeBox = false ;
this.MinimizeBox = false ;
this.WindowState = System.Windows.Forms.FormWindowState.Minimized ;
this.Name = "capture" ;
this.ShowInTaskbar = false ;
this.Text = "用C#做Screen Capture程序!" ;
this.ResumeLayout ( false ) ;
}
static void Main ( )
{
Application.Run ( new Capture ( ) ) ;
}
}
四. 总结:
虽然.Net FrameWork SDK的内容十分丰富,借助他所能够实现的功能也非常强大,但对于一些底层的操作,有时还是需要借助Windows的API函数才可以实现,而实现Screen Capture的关键也就在于掌握C#中调用API函数的方法。希望通过本文,能够对你掌握在C#中的API编程有所帮助。