隐藏任务栏
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
Win API
获取当前截图
//首先导入库文件
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
//声明函数
private static extern IntPtr CreateDC
(
string Driver, //驱动名称
string Device, //设备名称
string Output, //无用,可以设定为null
IntPtr PrintData //任意的打印机数据
);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, //目标设备的句柄
int XDest, //目标对象的左上角X坐标
int YDest, //目标对象的左上角的Y坐标
int Width, //目标对象的宽度
int Height, //目标对象的高度
IntPtr hdcScr, //源设备的句柄
int XScr, //源设备的左上角X坐标
int YScr, //源设备的左上角Y坐标
Int32 drRop //光栅的操作值
);
public Image getScreenShot() {
//this.Hide();
IntPtr dc1 = CreateDC("DISPLAY", null, null, (IntPtr)null);
//创建显示器的DC
Graphics g1 = Graphics.FromHdc(dc1);
//由一个指定设备的句柄创建一个新的Graphics对象
Bitmap MyImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, g1);
//根据屏幕大小创建一个与之相同大小的Bitmap对象
Graphics g2 = Graphics.FromImage(MyImage);
//获得屏幕的句柄
IntPtr dc3 = g1.GetHdc();
//获得位图的句柄
IntPtr dc2 = g2.GetHdc();
//把当前屏幕捕获到位图对象中
BitBlt(dc2, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc3, 0, 0, 13369376);
//把当前屏幕拷贝到位图中
g1.ReleaseHdc(dc3);
//释放屏幕句柄
g2.ReleaseHdc(dc2);
//释放位图句柄
return MyImage;
}