您的位置:首页 > 编程语言 > C#

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); } } }}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: