动态生成复选框
CheckBox[] cb=new CheckBox[n*n];
添加事件
cb[i].Click+=new System.EventHandler(this.MyClick);
在事件处理函数中
x=i/n;y=i%n;
cb[(x-1)*3+y].Clicked取反
cb[(x+1}*3+y].Clicked取反
cb[x*3+y-1].Clicked取反
cb[x*3+y+1].Clicked取反
(要自己判断是否越界)
CheckBox[] cb=new CheckBox[n*n];
添加事件
cb[i].Click+=new System.EventHandler(this.MyClick);
在事件处理函数中
x=i/n;y=i%n;
cb[(x-1)*3+y].Clicked取反
cb[(x+1}*3+y].Clicked取反
cb[x*3+y-1].Clicked取反
cb[x*3+y+1].Clicked取反
(要自己判断是否越界)
解决方案 »
- 【求助】C#怎样实现流氓软件效果
- C#怎样模拟post提交
- foreach Groupbox的问题再求解??(附图)
- Winform有像微软的那个“日期时间”控件吗?
- 一个存储过程问题,解决就给分
- picturebox 的paint函数中使用了refresh之后程序变得很慢,cpu100%,哪位大侠有好方法解决下??急!!
- 用一个字符串存放控件的类型,如何通过这个字符串在程序中动态生成相应类型的控件?召唤思归、速马等达人!!!
- 有没有人能修改schedulerControl1的AppointmentForm的
- 已知椭圆的长短半径,和起始角度,求圆心到该角度的坐标值
- 請問想在DataSet中把DataTable(table2)的內容 復制到另一個DataTable(table1)中,點做??
- 这段代码有问题吗?我怎么看不出来
- 关于C#使用api的问题!
using System.Drawing;
using System.Collections;
0Ausing System.ComponentModel;0D
using System.Windows.Forms;
using System.Data;namespace WindowsApplication11
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.CheckBox checkBoxSeed;
CheckBox[,] arrCB;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();//
// TODO: Add any constructor code after InitializeComponent call
//
}/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
0A}#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
0A/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.checkBoxSeed = new System.Windows.Forms.CheckBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// checkBoxSeed
//
this.checkBoxSeed.Location = new System.Drawing.Point(80, 96);
this.checkBoxSeed.Name = "checkBoxSeed";
this.checkBoxSeed.Size = new System.Drawing.Size(16, 16);
this.checkBoxSeed.TabIndex = 0;
this.checkBoxSeed.Text = "checkBoxSeed";
this.checkBoxSeed.Click += new System.EventHandler(this.checkBoxSeed_CheckedChanged);0D
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(184, 40);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {0D
this.button1,
this.checkBoxSeed});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
0A
}
#endregion/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());0D
}private void button1_Click(object sender, System.EventArgs e)
{
AddCheckBox(10,10);
}
private struct ArrLocation
0A{
public ArrLocation(int ii,int ij)
{
i=ii;
j=ij;
}
public int i;
public int j;
}
public void AddCheckBox(int row,int colomn){
arrCB=new CheckBox[row,colomn];
0APoint po=checkBoxSeed.Location;
Point p=po;for(int i=0;i<10;i++)
{
p.Y=po.Y;
p.Offset(20,0);
for(int j=0;j<10;j++)
{
arrCB[i,j]=new CheckBox();
//
// checkBoxSeed
//
p.Offset(0,20);
arrCB[i,j].Location=p;
arrCB[i,j].Name = "checkBox" + i.ToString() + j.ToString();
arrCB[i,j].Size = checkBoxSeed.Size;
arrCB[i,j].TabIndex = 0;
arrCB[i,j].Tag=new ArrLocation(i,j);
arrCB[i,j].Text = "";
arrCB[i,j].Click += new System.EventHandler(this.checkBoxSeed_CheckedChanged);0D
this.Controls.Add(arrCB[i,j]);}
}
this.ResumeLayout();}private void checkBoxSeed_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb=(CheckBox)sender;
ArrLocation al=(ArrLocation)cb.Tag;try
{
arrCB[al.i,al.j+1].Checked=!arrCB[al.i,al.j+1].Checked;arrCB[al.i,al.j-1].Checked=!arrCB[al.i,al.j-1].Checked;0DarrCB[al.i+1,al.j].Checked=!arrCB[al.i+1,al.j].Checked;arrCB[al.i-1,al.j].Checked=!arrCB[al.i-1,al.j].Checked;0D
}
catch(Exception ex)
{
Console.Write(ex);
}}private void Form1_Load(object sender, System.EventArgs e)0D
{}
}
}
// 新建一winform apllication,把这个整个拷贝进去。run一下就行了。
------------------------------
我是一只小小鸟
欢迎交流!
MSN&