截取全屏代码:

try
{
this.Hide();
Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));
Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);
Graphics g = Graphics.FromImage(bitmap);
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size); System.Threading.Thread.Sleep(50); SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "bmp files (*.bmp)|*.bmp";
saveFileDialog.Title = "保存文件";
saveFileDialog.ShowDialog();
bmpPath = saveFileDialog.FileName;
if ("" != bmpPath)
{
bitmap.Save(bmpPath, ImageFormat.Bmp);
}
bitmap.Dispose();
this.Show();
}
catch (System.Exception ex)
{
MessageBox.Show("抓图失败!");
this.Show();
}

frmChildScreen 窗体代码如下:

 private void frmChildScreen_Load(object sender, EventArgs e)
{
this.Cursor = Cursors.Cross; this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
this.UpdateStyles();
originBmp = new Bitmap(this.BackgroundImage);
} private void Catch_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (!catchStart)
{
catchStart = true;
startPoint = new Point(e.X, e.Y);
}
}
} private void Catch_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
} private void Catch_MouseMove(object sender, MouseEventArgs e)
{
if (catchStart)
{
Bitmap destBmp = (Bitmap)originBmp.Clone();
Point newPoint = new Point(startPoint.X, startPoint.Y);
Graphics g = Graphics.FromImage(destBmp);
Pen p = new Pen(Color.Blue, 1);
int width = Math.Abs(e.X - startPoint.X), height = Math.Abs(e.Y - startPoint.Y);
if (e.X < startPoint.X)
{
newPoint.X = e.X;
}
if (e.Y < startPoint.Y)
{
newPoint.Y = e.Y;
}
catchRect = new Rectangle(newPoint, new Size(width, height));
g.DrawRectangle(p, catchRect);
g.Dispose();
p.Dispose();
Graphics g1 = this.CreateGraphics();
g1 = this.CreateGraphics();
g1.DrawImage(destBmp, new Point(0, 0));
g1.Dispose();
destBmp.Dispose();
}
} private void Catch_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (catchStart)
{
catchStart = false;
catchFinish = true;
}
}
} private void Catch_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && catchFinish)
{
if (catchRect.Contains(new Point(e.X, e.Y)))
{
Bitmap bitmap = new Bitmap(catchRect.Width, catchRect.Height);
Graphics g = Graphics.FromImage(bitmap);
g.DrawImage(originBmp, new Rectangle(0, 0, bitmap.Width, bitmap.Height), catchRect, GraphicsUnit.Pixel); SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "bmp files (*.bmp)|*.bmp";
saveFileDialog.Title = "保存文件";
saveFileDialog.ShowDialog();
bmpPath = saveFileDialog.FileName;
if ("" != bmpPath)
{
bitmap.Save(bmpPath, ImageFormat.Bmp);
}
bitmap.Dispose();
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}

截取局部屏幕代码如下:

 try
{
this.Hide();
Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));

Thread.Sleep(50);
frmChildScreen CatchForm = new frmChildScreen();
Bitmap catchBmp = new Bitmap(bounds.Width, bounds.Height);
Graphics g = Graphics.FromImage(catchBmp);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height));
CatchForm.BackgroundImage = catchBmp;
if (CatchForm.ShowDialog() == DialogResult.OK)
{
this.Show();
}

}
catch (System.Exception e)
{
MessageBox.Show("抓图失败!");
this.Show();
}

winfrom 截屏、抓屏 分类: WinForm 2014-08-01 13:02 198人阅读 评论(0) 收藏的更多相关文章

  1. 棋盘问题 分类: 搜索 POJ 2015-08-09 13:02 4人阅读 评论(0) 收藏

    棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28474 Accepted: 14084 Description 在一 ...

  2. 【Heritrix基础教程之2】Heritrix基本内容介绍 分类: B1_JAVA H3_NUTCH 2014-06-01 13:02 878人阅读 评论(0) 收藏

    1.版本说明 (1)最新版本:3.3.0 (2)最新release版本:3.2.0 (3)重要历史版本:1.14.4 3.1.0及之前的版本:http://sourceforge.net/projec ...

  3. TinyXML2读取和创建XML文件 分类: C/C++ 2015-03-14 13:29 94人阅读 评论(0) 收藏

    TinyXML2是simple.small.efficient C++ XML文件解析库!方便易于使用,是对TinyXML的升级改写!源码见本人上传到CSDN的TinyXML2.rar资源:http: ...

  4. Segment Tree 分类: ACM TYPE 2014-08-29 13:04 97人阅读 评论(0) 收藏

    #include<iostream> #include<cstdio> using namespace std; struct node { int l, r, m; int ...

  5. JAVA swing中JPanel如何实现分组框的效果以及设置边框颜色 分类: Java Game 2014-08-16 12:21 198人阅读 评论(0) 收藏

    代码如下: import java.awt.FlowLayout; import java.awt.Frame; import java.awt.GridLayout; import javax.sw ...

  6. 积分图像的应用(一):局部标准差 分类: 图像处理 Matlab 2015-06-06 13:31 137人阅读 评论(0) 收藏

    局部标准差在图像处理邻域具有广泛的应用,但是直接计算非常耗时,本文利用积分图像对局部标准差的计算进行加速. 局部标准差: 标准差定义如下(采用统计学中的定义,分母为): 其中. 为了计算图像的局部标准 ...

  7. C# WinForm 透明控件 PictureBox透明 分类: WinForm 2014-07-30 13:27 591人阅读 评论(0) 收藏

    1.要实现C# WinForm中的控件与背景的透明,可以通过设置控件的BackColor属性为Transparent,同时设置其父控件.因为在C#中,控件的透明指对父窗体透明.如果不设置Parent属 ...

  8. winform datagridview如何获取索引 分类: DataGridView 2014-04-11 13:42 216人阅读 评论(0) 收藏

    datagridview.CurrentCell.RowIndex;            是当前活动的单元格的行的索引 datagridview.SelectedRows  ;           ...

  9. iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏

    youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...

随机推荐

  1. Qt5下的常见问题————C1083

    很多像我一样刚开始学习Qt的时候都会遇到这样的问题.例如"fatal error C1083: 无法打开包括文件:“QApplication”: No such file or direct ...

  2. Binary Tree Level Order Traversal 解题思路 ×

    要求: 树的层级遍历 思路: 1.两个队列,q1 q2 ,root放到q1 2.q1首元素出列,判断是否有左右孩子,有的话,放入q2.(循环此步骤值得q1为空) 3.q1 = q2,重复2,直到q1为 ...

  3. Linux环境下添加ftp账号步骤

    (1)远程登录Linux服务器所用的工具,免费开源,可以从网站上很容易就下载到. (2)打开putty,输入服务器IP,进入后按提示进入用户名和密码输入超级管理员 root,然后系统让输入密码,注意此 ...

  4. 【原创】win7同局域网下共享文件

    本文章用于解决win7局域网共享文件问题: 首先保证两台机器可以ping通: 检测方法: win+R输入cmd打开命令行,输入ping  对方主机ip 不知对方ip可以在在命令行中输入ipconfig ...

  5. C#程序中:如何删除xml文件中的节点、元素。

    C#中动态的清理xml文件中的垃圾信息是程序员必会的哦.这就像数据库一样,不会清理数据怎么可以呢?其实xml文件就可以用作一个小的数据库,存储一些简单的信息.所以,用C#程序实现xml文件的增.删.改 ...

  6. React 学习资源分享 菜鸟刚学5天 博客写的不多 不懂写博客的套路

    http://www.ruanyifeng.com/blog/2015/03/react.html 首先个人强烈推荐 阮一峰的React基础 细细过一遍,看得出大师的用心良苦 然后就开始看书般的过ht ...

  7. nginx服务器,php-fpm重启

    1.重启nginx服务器:首先whereis nginx找到你的nginx命令执行文件所在目录,直接/usr/local/nginx/sbin/nginx -s reload 这个路径可能每个人不一样 ...

  8. 那些年优秀的HTML5活动页面

    一个好的手机活动宣传 更能让人分享 传播是爆炸性的 下面是我平时看到一些好的微信活动宣传页面  分享给大家 其中用到的技术 常做微信活动 专题页面的人 可以看看大神们是怎么做的  这样到自己做的时候 ...

  9. 安装linux系统后要做的事情

    基本安装0 http://www.kali.org.cn/thread-20517-1-1.html 基本安装1 http://defcon.cn/1618.html 基本安装2 http://www ...

  10. Java Fluent Restful API自动化测试框架

    这是一个Restful API自动化测试框架,这是一个能让你写出高可读性测试代码的测试框架! 项目目标 话说目前行业内,Restful API自动化测试框架已经不是稀罕物了,各个语言都有自己的实现机制 ...