日期:2011-06-14  浏览次数:20607 次

前阵子改了段C#截图功能的代码,现贴上来希望对大家有用

主文件

CaptureScreenForm.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace CaptureScreen
{
 /// <summary>
 /// CaptureScreenForm 的摘要说明。
 /// </summary>
 public class CaptureScreenForm : System.Windows.Forms.Form
 {
  private System.Windows.Forms.PictureBox picbox;
  private System.Windows.Forms.Button exitBtn;
  private System.Windows.Forms.Button aboutBtn;
  private System.Windows.Forms.Button ClearBtn;
  private System.Windows.Forms.Button saveBtn;
  private System.Windows.Forms.Button fullScreenBtn;
  private System.Windows.Forms.Button mouseCaptureBtn;

  public static Image image = null ;
  private System.Windows.Forms.Panel panel1;

  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;

  public CaptureScreenForm()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.picbox = new System.Windows.Forms.PictureBox();
   this.fullScreenBtn = new System.Windows.Forms.Button();
   this.mouseCaptureBtn = new System.Windows.Forms.Button();
   this.ClearBtn = new System.Windows.Forms.Button();
   this.saveBtn = new System.Windows.Forms.Button();
   this.aboutBtn = new System.Windows.Forms.Button();
   this.exitBtn = new System.Windows.Forms.Button();
   this.panel1 = new System.Windows.Forms.Panel();
   this.panel1.SuspendLayout();
   this.SuspendLayout();
   //
   // picbox
   //
   this.picbox.Location = new System.Drawing.Point(0, 40);
   this.picbox.Name = "picbox";
   this.picbox.Size = new System.Drawing.Size(680, 312);
   this.picbox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
   this.picbox.TabIndex = 0;
   this.picbox.TabStop = false;
   //
   // fullScreenBtn
   //
   this.fullScreenBtn.Location = new System.Drawing.Point(0, 0);
   this.fullScreenBtn.Name = "fullScreenBtn";
   this.fullScreenBtn.Size = new System.Drawing.Size(96, 32);
   this.fullScreenBtn.TabIndex = 1;
   this.fullScreenBtn.Text = "全屏截取";
   this.fullScreenB