C#简易截图工具源码下载
2016-09-05 19:48
369 查看
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms; namespace 简易截图工具{ public partial class Form1 : Form { public static Form1 f1 = null;
public Form1() { InitializeComponent(); f1 = this; } public void Snap(int x, int y, int w, int h) { Image img = new Bitmap(w, h); PictureBox p = new PictureBox(); p.Image = img; Graphics g = Graphics.FromImage(img); g.CopyFromScreen(new Point(x, y), new Point(0,
0), new Size(w, h), CopyPixelOperation.SourceCopy); SaveFileDialog s = new SaveFileDialog(); s.DefaultExt = "*.jpg"; s.Filter = "图片类型(*.jpg)|*.jpg|bmp|*.bmp"; s.ShowDialog(); string name = s.FileName; if (s.FileName.ToString().Trim() != "") { p.Image.Save(name);
} } private void button1_Click(object sender, EventArgs e) { Form2 f = new Form2(); this.Hide(); f.ShowDialog(); } }}[/code]Form2代码[code=csharp]using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using
System.Linq;using System.Text;using System.Windows.Forms; namespace 简易截图工具{ public partial class Form2 : Form { bool ismousedomn = false; int x; int y; int nx; int ny; public Form2() { InitializeComponent(); this.Width = Screen.PrimaryScreen.WorkingArea.Width;
this.Height = Screen.PrimaryScreen.WorkingArea.Height; } private void Form2_MouseDown(object sender, MouseEventArgs e) { x = MousePosition.X; y = MousePosition.Y; ismousedomn = true; } private void Form2_MouseUp(object sender, MouseEventArgs e) { nx = MousePosition.X;
ny = MousePosition.Y; this.Close(); Form1.f1.Snap(x < nx ? x : nx, y < ny ? y : ny, Math.Abs(nx - x), Math.Abs(ny - y)); Form1.f1.Show(); } private void Form2_MouseMove(object sender, MouseEventArgs e) { if (ismousedomn) { int width = Math.Abs(MousePosition.X
- x); int height = Math.Abs(MousePosition.Y - y); Graphics g = this.CreateGraphics(); g = CreateGraphics(); g.DrawRectangle(new Pen(Color.Red,8),x<MousePosition.X?x:MousePosition.X,y<MousePosition.Y?y:MousePosition.Y,width+1,height+1); } } }}
public Form1() { InitializeComponent(); f1 = this; } public void Snap(int x, int y, int w, int h) { Image img = new Bitmap(w, h); PictureBox p = new PictureBox(); p.Image = img; Graphics g = Graphics.FromImage(img); g.CopyFromScreen(new Point(x, y), new Point(0,
0), new Size(w, h), CopyPixelOperation.SourceCopy); SaveFileDialog s = new SaveFileDialog(); s.DefaultExt = "*.jpg"; s.Filter = "图片类型(*.jpg)|*.jpg|bmp|*.bmp"; s.ShowDialog(); string name = s.FileName; if (s.FileName.ToString().Trim() != "") { p.Image.Save(name);
} } private void button1_Click(object sender, EventArgs e) { Form2 f = new Form2(); this.Hide(); f.ShowDialog(); } }}[/code]Form2代码[code=csharp]using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using
System.Linq;using System.Text;using System.Windows.Forms; namespace 简易截图工具{ public partial class Form2 : Form { bool ismousedomn = false; int x; int y; int nx; int ny; public Form2() { InitializeComponent(); this.Width = Screen.PrimaryScreen.WorkingArea.Width;
this.Height = Screen.PrimaryScreen.WorkingArea.Height; } private void Form2_MouseDown(object sender, MouseEventArgs e) { x = MousePosition.X; y = MousePosition.Y; ismousedomn = true; } private void Form2_MouseUp(object sender, MouseEventArgs e) { nx = MousePosition.X;
ny = MousePosition.Y; this.Close(); Form1.f1.Snap(x < nx ? x : nx, y < ny ? y : ny, Math.Abs(nx - x), Math.Abs(ny - y)); Form1.f1.Show(); } private void Form2_MouseMove(object sender, MouseEventArgs e) { if (ismousedomn) { int width = Math.Abs(MousePosition.X
- x); int height = Math.Abs(MousePosition.Y - y); Graphics g = this.CreateGraphics(); g = CreateGraphics(); g.DrawRectangle(new Pen(Color.Red,8),x<MousePosition.X?x:MousePosition.X,y<MousePosition.Y?y:MousePosition.Y,width+1,height+1); } } }}
相关文章推荐
- C# 开发系列(二)
- C#控制台基础 给一个字符串是文件的全称,分离出来文件的类型与名字
- C#控制台基础 找到一个字符串中一个字符的所有索引值
- C#控制台基础 将字符串中的指定的特殊字符串替换掉
- C# 开发系列(一)
- C#控制台基础 使用split分离字符串出现了很多的空,怎么除去空
- C# XML文件的一些操作,增删改查
- 《C#高级编程》读书笔记(十七):事务
- C#解析XML
- C#控制台基础 给一个邮箱,分离出用户名和域名
- C#控制台基础 将以-分割的年月日转换为x年x月x日,用split
- C#调用win32 api字典
- c#中数组赋值方法
- C#获取客户端浏览器信息
- C#获取本地IP
- C# 将应用程序显示在扩展桌面
- C#控制台基础 比较两个字符串,无视大小写
- .net c# vs自动递增版本号
- C# AttributeUsage的使用浅析
- C# Lock 解读[转]