截取全屏代码:

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. angularjs跨域调取webservice

    1.配置 web.config <webServices> <!--必须添加--> <protocols> <add name="HttpGet&q ...

  2. php函数应用场景

    截取文件后缀: $slen = strlen($suffix); substr($this->uri_string, -$slen) === $suffix 原理:截取倒数多少长度字符 判断多维 ...

  3. centos7 更改语言

    vim /etc/locale.conf 修改 LANG="en_US.UTF-8"

  4. "System.Web" 中不存在类型或命名空间

    System.Web”中不存在类型或命名空间名称script  /找不到System.Web.Extensions.dll引用 添加引用就行了...“添加引用→.Net→System.Web.Ente ...

  5. Django国际化注意事项

    涉及两部分内容: py/html文件国际化.外部js文件国际化 步骤 1. settings.py 激活相应的配置 2. 针对py文件,需要注意被翻译代码的编写方式 3. 针对html文件,需要注意被 ...

  6. SEMAT[软件工程方法和理论 Software Engineering Method and Theory]

    Agile software development Agile software development is a group of software development methods bas ...

  7. union 与struct的空间计算

    一.x86 总体上遵循两个原则: 整体空间----占用空间最大的成员(的类型)所占字节数的整数倍 对齐原则----内存按结构成员的先后顺序排列,当排到该成员变量时,其前面已摆放的空间大小必须是该成员类 ...

  8. [原创]dm642_HPI调通并boot成功

    一直在折腾前段时间画好的dm642+lpc4357板子,说明下这个板子的结构: 主芯片为DM642,这个片子很老了,但因为对这个片子熟悉,别折腾 没有给DM642加FLASH,配了一片LPC4357, ...

  9. bzoj 1034: [ZJOI2008]泡泡堂BNB 貪心

    1034: [ZJOI2008]泡泡堂BNB Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1398  Solved: 727[Submit][Sta ...

  10. [BZOJ 1106] [POI2007] 立方体大作战tet 【树状数组】

    题目链接:BZOJ - 1106 题目分析 从1到2n枚举每一个位置. 如果枚举到某一个数,这个数已经是第二次出现,那么就看它和第一次出现的位置之间有多少数还没有被匹配,有多少没有匹配的就要进行多少次 ...