C#简易截图工具源码下载

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); } } }}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值