简单截图软件实现原理
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;
using System.Drawing.Drawing2D;
namespace jietu
{
public partial class benginok : Form
{
public benginok()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void buttok_Click(object sender, EventArgs e)
{ //隐藏窗体;
this.Hide();
//启动定时器,1.5秒后开始截图,以便于隐藏窗体。
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
//停止定时器;
timer1.Stop();
Bitmap bit = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(bit);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), bit.Size);
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "bmp|*.bmp|jpg|*.jpg|gif|*.gif";
if (saveFileDialog.ShowDialog() != DialogResult.Cancel)
{
bit.Save(saveFileDialog.FileName);
}
g.Dispose();
this.Visible = true;
}
}
}
浙公网安备 33010602011771号