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);
}
}
}
填充不了

解决方案 »

  1.   

    要正常填充需要设置PictureBox的FillStyle和FillColor属性。FillStyle设置用来填充的模式。缺省值是透明,也就是不填充。你可以设置为其他值。FillColor属性是用来填充的颜色,如果你希望用红色填充区域需要设置这个属性为红色。FloodFill的最后一个参数是填充区域边界的颜色。
      

  2.   

    大虾说的是VB吧,C#中pictureBox没有FillStyle和FIllColor属性.你说好像不对