屏幕截图
private void cutScreen()
{
ini_init();
try
{
this.WindowState = FormWindowState.Minimized; //最小化当前窗口
Thread.Sleep(500);//延时2秒
if (Directory.Exists(mypath)) //判断目录是否存在,不存在就创建
{ }
else
{
DirectoryInfo directoryInfo = new DirectoryInfo(mypath);
directoryInfo.Create();
}
//创建图片对象
Bitmap bmp2 = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g2 = Graphics.FromImage(bmp2); //创建画笔
g2.CopyFromScreen(new Point(0, 0), new Point(0, 0), bmp2.Size);//截屏
string time = DateTime.Now.ToString("yyyy-MM-dd HHmmssfff");//获得系统时间
//time = System.Text.RegularExpressions.Regex.Replace(time, @"[^0-9]+", "");//提取数字
string fileName = mypath +@"\"+ time + ".bmp"; //创建文件名
bmp2.Save(fileName); //保存为文件 ,注意格式是否正确.
bmp2.Dispose();//关闭对象
g2.Dispose();//关闭画笔
label1.Text = "截图成功";
Thread.Sleep(500);//延时2秒
this.WindowState = FormWindowState.Maximized; //最小化当前窗口
pictureBox1.Image = Image.FromFile(fileName);
if (autoexit == "1")
{
checkBox2.Checked = true;
Thread.Sleep(1000);
DialogResult dr = MessageBox.Show("是否退出", "结束截图", MessageBoxButtons.YesNoCancel);
if (dr == DialogResult.OK)
{
this.Dispose();
}
}
}
catch (Exception cse)
{
label1.Text = cse.ToString();
}
}