这是我的代码,和你的一样,但是不行的,要不你试试我的,看能不能找到好的解决方案
[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern int BitBlt(HandleRef hDC, int x, int y, int nWidth, int nHeight, HandleRef hSrcDC, int xSrc, int ySrc, int dwRop);
#endregion
//截图保存图片
private void ScreenShuts(int intX, int intY, int intWidth, int intHeight, int intLeft, int intRight, string strPicName)
{
获得当前窗体的大小
Rectangle rect = new Rectangle();
rect = this.Bounds;
//创建一个以当前窗体为模板的图象
Graphics g1 = this.CreateGraphics();
//创建以窗体大小为标准的位图
Bitmap MyBMP = new Bitmap(intWidth, intHeight, g1);//定义位图的大小
//创建一个位图Bitmap绘图图面
Graphics g2 = Graphics.FromImage(MyBMP);
//得到窗体的DC(句柄)
IntPtr dc1 = g1.GetHdc();
HandleRef hDcSrc = new HandleRef(null, dc1);
//得到Bitmap的DC
IntPtr dc2 = g2.GetHdc();
HandleRef hDcSave = new HandleRef(null, dc2);
//复制图块的光栅操作码
const int SRCCOPY = 0xcc0020;
//调用此API函数,实现窗体捕获
//BitBlt(dc2, intX, intY, intWidth, intHeight, dc1, intLeft, intRight, SRCCOPY);//13369376
BitBlt(hDcSave, intX, intY, intWidth, intHeight, hDcSrc, intLeft, intRight, SRCCOPY);//13369376
//释放掉屏幕的DC
g1.ReleaseHdc(dc1);
//释放掉Bitmap的DC
g2.ReleaseHdc(dc2);
//以JPG文件格式来保存
MyBMP.Save(Application.StartupPath + "\\路径\\" + strPicName, ImageFormat.Bmp);
}