C完整的截屏源代码及注释
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的句柄
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.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
//
/
/
// 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.Box1);
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窗⼝,浏览以下⽹页
}
}
}
}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。