windowsには、snipping toolという、画面キャプチャがあって、画面の一部分をクリッピングできるが、連続で切り抜いて、文書にぺたぺた貼っていくような場面には向かないので、csharpで、画面に常駐するクリッピングツールをつくった
scr_cap.cs
//コンパイルは、コマンドラインから以下
//c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:winexe scr_cap.cs
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
namespace scr_cap
{
public class Form1 : Form
{
public Button button1;
public Form1()
{
this.Text = "scr_cap";
this.TransparencyKey = this.BackColor;
this.TopMost = true;
//this.SizeGripStyle = 1;
this.FormBorderStyle = FormBorderStyle.Sizable;
button1 = new Button();
button1.Size = new Size(30, 1000);
button1.Location = new Point(0, 0);
button1.Text = "-";
this.Controls.Add(button1);
button1.Click += new EventHandler(button1_Click);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
var r = this.ClientRectangle;
var bmp = new Bitmap(r.Width-30, r.Height, PixelFormat.Format32bppArgb);
var g = Graphics.FromImage(bmp);
var iSource = this.PointToScreen(new Point(30, 0));
var iDestination = new Point(0, 0);
g.CopyFromScreen(
iSource, iDestination,
this.ClientSize, CopyPixelOperation.SourceCopy);
//bmp.Save(".\\capture.png", ImageFormat.Png);
Pen redPen = new Pen(Color.Red, 1);
Rectangle rect = new Rectangle(0, 0, bmp.Width-1,bmp.Height-1);
g.DrawRectangle(redPen, rect);
Clipboard.SetDataObject(bmp, true, 20, 500);
}
catch(Exception ex)
{
MessageBox.Show("エラー:\n\n" + ex);//
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
}