private void arryCB()
{GroupBox[] gb=new GroupBox[9];
int i;
int n=0;//读取项目
int gbb=0;//groupbox bing
int row;//gropubox row
int beforeRow=0;//上一个的行数
string[,] tt=new string[9,30];
CheckBox[,] cb=new CheckBox[9,30];
string[] filename={"content0.txt","content1.txt","content2.txt","content3.txt","content4.txt","content5.txt","content6.txt","content7.txt","content8.txt"};
for (i=0;i<8;i++)
{
gb[i]=new GroupBox();
//gb[i].Name = "groupBox8";
gb[i].TabIndex =i ;
gb[i].TabStop = false;
gb[i].Text = i.ToString();
gb[i].Visible=true;
this.tabPage1.Controls.Add(gb[i]);
StreamReader sr=new StreamReader(filename[i],System.Text.Encoding.GetEncoding("gb2312"));//循环读文件中的内容 int y=20;//
int x=0;//定义位置
while ((tt[i,n]=sr.ReadLine())!=null)
{
cb[i,n]=new CheckBox();
cb[i,n].Location = new System.Drawing.Point(90*x+10,y);
cb[i,n].Name = "checkBox1";
cb[i,n].TabIndex =n;
cb[i,n].Text = tt[i,n];
cb[i,n].Size=new System.Drawing.Size(15*tt[i,n].Length+20, 20);
gb[i].Controls.Add(cb[i,n]); n++; if ((n%6)==0)
{
y=y+24;
x=0;
}
else
{
x++;
}
//****************************
}
if ((n/6)==0)
{
row=n/6;
}
else
{
row=(n / 6+1);
}
if (i==0)
{
gb[i].Location = new System.Drawing.Point(24, 10);
gbb=10;
beforeRow=row;
}
else
{
gb[i].Location = new System.Drawing.Point(24, 10+beforeRow*35+gbb);
gbb=10+beforeRow*35+gbb;
gb[i].Text+=beforeRow.ToString();
beforeRow=row;
} gb[i].Size = new System.Drawing.Size(560, 35*row);
//b[i]=n;
n=0;
sr.Close(); }
}
{GroupBox[] gb=new GroupBox[9];
int i;
int n=0;//读取项目
int gbb=0;//groupbox bing
int row;//gropubox row
int beforeRow=0;//上一个的行数
string[,] tt=new string[9,30];
CheckBox[,] cb=new CheckBox[9,30];
string[] filename={"content0.txt","content1.txt","content2.txt","content3.txt","content4.txt","content5.txt","content6.txt","content7.txt","content8.txt"};
for (i=0;i<8;i++)
{
gb[i]=new GroupBox();
//gb[i].Name = "groupBox8";
gb[i].TabIndex =i ;
gb[i].TabStop = false;
gb[i].Text = i.ToString();
gb[i].Visible=true;
this.tabPage1.Controls.Add(gb[i]);
StreamReader sr=new StreamReader(filename[i],System.Text.Encoding.GetEncoding("gb2312"));//循环读文件中的内容 int y=20;//
int x=0;//定义位置
while ((tt[i,n]=sr.ReadLine())!=null)
{
cb[i,n]=new CheckBox();
cb[i,n].Location = new System.Drawing.Point(90*x+10,y);
cb[i,n].Name = "checkBox1";
cb[i,n].TabIndex =n;
cb[i,n].Text = tt[i,n];
cb[i,n].Size=new System.Drawing.Size(15*tt[i,n].Length+20, 20);
gb[i].Controls.Add(cb[i,n]); n++; if ((n%6)==0)
{
y=y+24;
x=0;
}
else
{
x++;
}
//****************************
}
if ((n/6)==0)
{
row=n/6;
}
else
{
row=(n / 6+1);
}
if (i==0)
{
gb[i].Location = new System.Drawing.Point(24, 10);
gbb=10;
beforeRow=row;
}
else
{
gb[i].Location = new System.Drawing.Point(24, 10+beforeRow*35+gbb);
gbb=10+beforeRow*35+gbb;
gb[i].Text+=beforeRow.ToString();
beforeRow=row;
} gb[i].Size = new System.Drawing.Size(560, 35*row);
//b[i]=n;
n=0;
sr.Close(); }
}
解决方案 »
- c#中什么是引用?详细点得理论解答
- VS 2008 WebBrowser相关
- 我用的vs2005 做 winform开发,DataGridView 怎么没有 RowDataBound 事件!
- C#与matlab的通信问题
- C# piml模块的编程…………返回error
- 我写的C#串口类(有问题啊,读操作超时,GG们看看吧。)
- List<PointPair>类中,Find方法如何使用啊?
- DataSet中Table合并问题
- winform中sidebar控件如何使用
- C# Winform的AxShockwaveFlash控件如何播放不同的flv文件
- 怎样获得一个对象的属性并判断属性值是否为默认值?
- 怎样有选择地获取某个目录下的某些类型文件?
则tt[i,n]=sr.ReadLine())不就越界了吗?while ((tt[i,n]=sr.ReadLine())!=null)
{
cb[i,n]=new CheckBox();
cb[i,n].Location = new System.Drawing.Point(90*x+10,y);
cb[i,n].Name = "checkBox1";
cb[i,n].TabIndex =n;
cb[i,n].Text = tt[i,n];
cb[i,n].Size=new System.Drawing.Size(15*tt[i,n].Length+20, 20);
gb[i].Controls.Add(cb[i,n]); n++; if ((n%6)==0)
{
y=y+24;
x=0;
}
else
{
x++;
}
//****************************
}
==>那时自然,出了这个函数,该函数定义的局部变量当然不能访问了。可以在class级定义这些需要引用的控件数组。如:
public class MyControls
{
GroupBox[] gb=new GroupBox[9]; CheckBox[,] cb=new CheckBox[9,30]; //............
private void arryCB(){...}
}