using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace getpixl
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
Bitmap bitmap=null;
Graphics ig =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 );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.pictureBox1.Location = new System.Drawing.Point(16, 24);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(760, 544);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(760, 574);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
[ System.Runtime.InteropServices.DllImportAttribute ( "gdi32.dll" , EntryPoint="FloodFill")]
static extern int FloodFill( IntPtr hDC , int X , int Y ,int newColor);
private void Form1_Load(object sender, System.EventArgs e)
{
/*bitmap = new Bitmap (pictureBox1 .Width ,pictureBox1 .Height );
Graphics g=pictureBox1.CreateGraphics();
Pen curpen=new Pen(Color.Black);
g.DrawRectangle(curpen,10,10,100,100);
ig.DrawRectangle(curpen,10,10,100,100);
pictureBox1.Image=bitmap;*/
}
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{ bitmap = new Bitmap (pictureBox1 .Width ,pictureBox1 .Height );
ig = Graphics.FromImage (bitmap);
IntPtr dc=ig.GetHdc();
Color newColor=Color.Black;
int oldColor=newColor.ToArgb();
FloodFill( dc, e.X , e.Y , oldColor);
pictureBox1.Image=bitmap;
ig.ReleaseHdc(dc);
}
}
}