注册后可以直接下载
截图工具.rar
(49.68 KB, 下载次数: 523)
效果如下
Form1代码
[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);
}
}
}
}
|