using
System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WindowsApplication4
... {
/**//**//**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private Image bm;
private System.Windows.Forms.TextBox textBox1;
/**//**//**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
[ System.Runtime.InteropServices.DllImportAttribute ( "gdi32.dll" ) ]
private static extern bool BitBlt (
IntPtr hdcDest , //目标设备的句柄
int nXDest , // 目标对象的左上角的X坐标
int nYDest , // 目标对象的左上角的X坐标
int nWidth , // 目标对象的矩形的宽度
int nHeight , // 目标对象的矩形的长度
IntPtr hdcSrc , // 源设备的句柄
int nXSrc , // 源对象的左上角的X坐标
int nYSrc , // 源对象的左上角的X坐标
System.Int32 dwRop // 光栅的操作值
) ;
[ System.Runtime.InteropServices.DllImportAttribute ( "gdi32.dll" ) ]
private static extern IntPtr CreateDC (
string lpszDriver , // 驱动名称
string lpszDevice , // 设备名称
string lpszOutput , // 无用,可以设定位"NULL"
IntPtr lpInitData // 任意的打印机数据
) ;
public Form1()
...{
Screen scr=Screen.AllScreens[0];
string str=scr.Bounds.Height+":"+scr.Bounds.Width;
//MessageBox.Show(str);
IntPtr dc1=CreateDC("DISPLAY",null,null,(IntPtr)null);
Graphics g1=Graphics.FromHdc(dc1);
bm=new Bitmap(scr.Bounds.Width,scr.Bounds.Height,g1);
Graphics g2=Graphics.FromImage(bm);
IntPtr dc2=g1.GetHdc();
IntPtr dc3=g2.GetHdc();
BitBlt(dc3,0,0,scr.Bounds.Width,scr.Bounds.Height,dc2,0,0,13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc3);
g1.Dispose();
g2.Dispose();
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
bm.Save("d:/a.jpg");
}
/**//**//**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//**//**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(208, 64);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(704, 293);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Resize += new System.EventHandler(this.Form1_Resize);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.ResumeLayout(false);
}
#endregion
/**//**//**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new Form1());
}
protected void Form1_Paint(object sender, PaintEventArgs e)
...{
this.Invalidate(null,true);
}
protected override void OnPaint ( System.Windows.Forms.PaintEventArgs e )
...{
Graphics g3=this.CreateGraphics();
PointF ulCorner = new PointF(0,0);
PointF urCorner = new PointF(this.Right-10,0);
textBox1.Text=this.Right+":"+this.Bottom;
PointF llCorner = new PointF(0,this.Bottom-10);
PointF[] destPara = ...{ulCorner, urCorner, llCorner};
g3.DrawImage(bm,destPara);
Graphics cjg=this.CreateGraphics();
Pen cjpen=new Pen(Color.Red);
cjg.DrawLine(cjpen,0,0,this.Right+200,this.Bottom);
//this.BackgroundImage=bm;
}
/**//*private void Form1_Activated(object sender, EventArgs e)
{
Graphics g3=this.CreateGraphics();
PointF ulCorner = new PointF(0,0);
PointF urCorner = new PointF(600,0);
PointF llCorner = new PointF(0,300);
PointF[] destPara = {ulCorner, urCorner, llCorner};
g3.DrawImage(bm,destPara);
}*/
private void Form1_Resize(object sender, EventArgs e)
...{
this.Invalidate(null,true);
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WindowsApplication4
... {
/**//**//**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private Image bm;
private System.Windows.Forms.TextBox textBox1;
/**//**//**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
[ System.Runtime.InteropServices.DllImportAttribute ( "gdi32.dll" ) ]
private static extern bool BitBlt (
IntPtr hdcDest , //目标设备的句柄
int nXDest , // 目标对象的左上角的X坐标
int nYDest , // 目标对象的左上角的X坐标
int nWidth , // 目标对象的矩形的宽度
int nHeight , // 目标对象的矩形的长度
IntPtr hdcSrc , // 源设备的句柄
int nXSrc , // 源对象的左上角的X坐标
int nYSrc , // 源对象的左上角的X坐标
System.Int32 dwRop // 光栅的操作值
) ;
[ System.Runtime.InteropServices.DllImportAttribute ( "gdi32.dll" ) ]
private static extern IntPtr CreateDC (
string lpszDriver , // 驱动名称
string lpszDevice , // 设备名称
string lpszOutput , // 无用,可以设定位"NULL"
IntPtr lpInitData // 任意的打印机数据
) ;
public Form1()
...{
Screen scr=Screen.AllScreens[0];
string str=scr.Bounds.Height+":"+scr.Bounds.Width;
//MessageBox.Show(str);
IntPtr dc1=CreateDC("DISPLAY",null,null,(IntPtr)null);
Graphics g1=Graphics.FromHdc(dc1);
bm=new Bitmap(scr.Bounds.Width,scr.Bounds.Height,g1);
Graphics g2=Graphics.FromImage(bm);
IntPtr dc2=g1.GetHdc();
IntPtr dc3=g2.GetHdc();
BitBlt(dc3,0,0,scr.Bounds.Width,scr.Bounds.Height,dc2,0,0,13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc3);
g1.Dispose();
g2.Dispose();
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
bm.Save("d:/a.jpg");
}
/**//**//**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//**//**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(208, 64);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(704, 293);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Resize += new System.EventHandler(this.Form1_Resize);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.ResumeLayout(false);
}
#endregion
/**//**//**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new Form1());
}
protected void Form1_Paint(object sender, PaintEventArgs e)
...{
this.Invalidate(null,true);
}
protected override void OnPaint ( System.Windows.Forms.PaintEventArgs e )
...{
Graphics g3=this.CreateGraphics();
PointF ulCorner = new PointF(0,0);
PointF urCorner = new PointF(this.Right-10,0);
textBox1.Text=this.Right+":"+this.Bottom;
PointF llCorner = new PointF(0,this.Bottom-10);
PointF[] destPara = ...{ulCorner, urCorner, llCorner};
g3.DrawImage(bm,destPara);
Graphics cjg=this.CreateGraphics();
Pen cjpen=new Pen(Color.Red);
cjg.DrawLine(cjpen,0,0,this.Right+200,this.Bottom);
//this.BackgroundImage=bm;
}
/**//*private void Form1_Activated(object sender, EventArgs e)
{
Graphics g3=this.CreateGraphics();
PointF ulCorner = new PointF(0,0);
PointF urCorner = new PointF(600,0);
PointF llCorner = new PointF(0,300);
PointF[] destPara = {ulCorner, urCorner, llCorner};
g3.DrawImage(bm,destPara);
}*/
private void Form1_Resize(object sender, EventArgs e)
...{
this.Invalidate(null,true);
}
}
}