C#完整的截屏源代码及注释

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

/*
这是一个完整的截屏程序,调试通过,你可以根据昨天的,窗口杀手程序,也给这个截屏加上热键,和窗口放到系统托盘上,这样,截屏就不会将程序本身也给显示在截出来的图片上了。过两天,我会写上这两个功能的。不过,最好,你能自己也试试。
可以在这儿下载http://metababy.chinay.com/sp/metababy/08383052696.rar源文件的打包
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 截屏
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.TextBox textBox1;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.LinkLabel linkLabel1;
  private System.Windows.Forms.LinkLabel linkLabel2;
  private System.Windows.Forms.LinkLabel linkLabel3;
  private System.Windows.Forms.LinkLabel linkLabel4;
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;

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

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

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }
[ System.Runtime.InteropServices.DllImportAttribute ( "gdi32.dll" ) ]
  private static extern bool BitBlt (
 IntPtr hdcDest , // 目标 DC的句柄
 int nXDest ,
 int nYDest , 
 int nWidth ,
 int nHeight ,
 IntPtr hdcSrc ,  // 源DC的句柄
 int nXSrc ,
 int nYSrc ,
 System.Int32 dwRop  // 光栅的处理数值
 ) ;//这儿,我也没搞清楚,知其然不知所以然,这些参数的具体意义,我还得找找资料,有朋友知道的,请回复在评论里,谢谢
  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
   this.button1 = new System.Windows.Forms.Button();
   this.textBox1 = new System.Windows.Forms.TextBox();
   this.label1 = new System.Windows.Forms.Label();
   this.linkLabel1 = new System.Windows.Forms.LinkLabel();
   this.linkLabel2 = new System.Windows.Forms.LinkLabel();
   this.linkLabel3 = new System.Windows.Forms.LinkLabel();
   this.linkLabel4 = new System.Windows.Forms.LinkLabel();
   this.SuspendLayout();
   //
   // button1
   //
   this.button1.Location = new System.Drawing.Point(24, 120);
   this.button1.Name = "button1";
   this.button1.TabIndex = 0;
   this.button1.Text = "截屏";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // textBox1
   //
   this.textBox1.Location = new System.Drawing.Point(24, 64);
   this.textBox1.Name = "textBox1";
   this.textBox1.Size = new System.Drawing.Size(184, 21);
   this.textBox1.TabIndex = 1;
   this.textBox1.Text = "c://花纯春.jpg";
   //
   // label1
   //
   this.label1.Location = new System.Drawing.Point(24, 40);
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(168, 23);
   this.label1.TabIndex = 2;
   this.label1.Text = "请输入图片存放位置及名称";
   //
   // linkLabel1
   //
   this.linkLabel1.Location = new System.Drawing.Point(24, 176);
   this.linkLabel1.Name = "linkLabel1";
   this.linkLabel1.TabIndex = 3;
   this.linkLabel1.TabStop = true;
   this.linkLabel1.Text = "我的小店";
   this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
   //
   // linkLabel2
   //
   this.linkLabel2.Location = new System.Drawing.Point(136, 176);
   this.linkLabel2.Name = "linkLabel2";
   this.linkLabel2.TabIndex = 4;
   this.linkLabel2.TabStop = true;
   this.linkLabel2.Text = "我的blog主力站";
   this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked);
   //
   // linkLabel3
   //
   this.linkLabel3.Location = new System.Drawing.Point(24, 224);
   this.linkLabel3.Name = "linkLabel3";
   this.linkLabel3.TabIndex = 5;
   this.linkLabel3.TabStop = true;
   this.linkLabel3.Text = "我的blog备用站";
   this.linkLabel3.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel3_LinkClicked);
   //
   // linkLabel4
   //
   this.linkLabel4.Location = new System.Drawing.Point(136, 224);
   this.linkLabel4.Name = "linkLabel4";
   this.linkLabel4.TabIndex = 6;
   this.linkLabel4.TabStop = true;
   this.linkLabel4.Text = "我的MSN空间";
   this.linkLabel4.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel4_LinkClicked);
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(292, 266);
   this.Controls.Add(this.linkLabel4);
   this.Controls.Add(this.linkLabel3);
   this.Controls.Add(this.linkLabel2);
   this.Controls.Add(this.linkLabel1);
   this.Controls.Add(this.label1);
   this.Controls.Add(this.textBox1);
   this.Controls.Add(this.button1);
   this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
   this.Name = "Form1";
   this.Text = "花纯春写的截屏练习程序";
   this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  private void button1_Click(object sender, System.EventArgs e)
  {
   
   try
   {

  
    //获得当前屏幕的大小
    Rectangle rect = new Rectangle ( ) ;
    rect = Screen.GetWorkingArea ( this ) ;
    //创建一个以当前屏幕为模板的图象
    Graphics g1 = this.CreateGraphics ( ) ;
    //创建以屏幕大小为标准的位图
    Image MyImage = new Bitmap ( rect.Width , rect.Height , g1 ) ;
    Graphics g2 = Graphics.FromImage ( MyImage ) ;
    //得到屏幕的DC
    IntPtr dc1 = g1.GetHdc ( ) ;
    //得到Bitmap的DC
    IntPtr dc2 = g2.GetHdc ( ) ;
    //调用此API函数,实现屏幕捕获
    BitBlt ( dc2 , 0 , 0 , rect.Width , rect.Height , dc1 , 0 , 0 , 13369376 ) ;
    //释放掉屏幕的DC
    g1.ReleaseHdc ( dc1 ) ;
    //释放掉Bitmap的DC
    g2.ReleaseHdc ( dc2 ) ;
    //以JPG文件格式来保存
    MyImage.Save ( textBox1.Text ,ImageFormat.Jpeg);
    string a="当前屏幕已经保存到"+textBox1.Text;
    MessageBox.Show ( a ) ;
   }
   catch{MessageBox.Show("出错!");}
  }//以下是四个超链接的代码,点击就打开IE窗口,浏览以下网页

  private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
  {
   System.Diagnostics.Process.Start("http://shop1471977.taobao.com");

  }

  private void linkLabel2_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
  {
   System.Diagnostics.Process.Start("http://riji.163.com/weblog/page/metababy");

  }

  private void linkLabel3_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
  {
   System.Diagnostics.Process.Start("http://blog.csdn.net/metababy");

  }

  private void linkLabel4_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
  {
   System.Diagnostics.Process.Start("http://spaces.msn.com/members/metababy/");

  }
 }
}

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值