使用下面的函数:public  Bitmap CaptureDesktopWindow()
{
//创建屏幕句柄
// Graphics grpWindow =Graphics.FromHwnd(IntPtr.Zero);
Graphics grpWindow=this.CreateGraphics();
Bitmap bitmap = new Bitmap((int)grpWindow.VisibleClipBounds.Width, (int)grpWindow.VisibleClipBounds.Height, grpWindow);

Graphics grpBitmap = Graphics.FromImage(bitmap);


IntPtr hdcWindow = grpWindow.GetHdc();


IntPtr hdcBitmap = grpBitmap.GetHdc();


Gdi32.BitBlt(hdcBitmap, 0, 0, bitmap.Width, bitmap.Height, hdcWindow, 0, 0, 0x00CC0020);

grpBitmap.ReleaseHdc(hdcBitmap);

grpWindow.ReleaseHdc(hdcWindow); grpBitmap.Dispose();

grpWindow.Dispose(); return bitmap;
}
得到屏幕图象,在非MDI窗体下运行正常,但是如果是MDI自窗体的话捕捉到的图象总是MDI应用程序Z序后面那个图象,也就是如果只运行了一个MDI程序那捕捉到的就是桌面背景。而且当前窗口显示的还是这个MDI程序,实在不知道是什么原因了。

解决方案 »

  1.   

    你要做什么,按照
    Graphics grpWindow=this.CreateGraphics();
    这句话的意思,你是要捕捉当前窗体的图形?
      

  2.   

    我要捕捉当前屏幕
    原来是用Graphics grpWindow =Graphics.FromHwnd(IntPtr.Zero);也是不行?
      

  3.   

    在C#中实现截屏功能:
    http://community.csdn.net/Expert/topic/4589/4589829.xml?temp=.9946863
      

  4.   

    那你参看
    http://www.syncfusion.com/faq/windowsforms/search/625.aspx
      

  5.   

    http://www.c-sharpcorner.com/Code/2003/Dec/ScreenCapture.asp