关于容器中的控件遍历问题
代码如下
//添加一个RadioButton 控件 .然后计算新控件显示位置
public void addNpc(Image img, int atype, int asubtype)
{
RadioButton rb = new RadioButton();
rb.Appearance = Appearance.Button;
rb.AutoSize = true;
rb.Location = new System.Drawing.Point(0, 0);
rb.Size = new System.Drawing.Size(32, 32);
rb.AutoSize = false;
rb.BackgroundImage = img;
rb.BackgroundImageLayout = ImageLayout.Zoom;
rb.TabStop = true;
rb.UseVisualStyleBackColor = true;
rb.Tag = new Point(atype, asubtype);
this.panel1.Controls.Add(rb);
calculateSize();
}
private int rbNumInCol;
private int rbNumInRow;
public void calculateSize()
{
panel1.Width = this.Width;
rbNumInCol = panel1.Width / 50;
rbNumInRow = rbsCnt / rbNumInCol;
if (rbsCnt % rbNumInCol != 0) rbNumInRow++;
panel1.Height = rbNumInRow * 40;
int tx = 0;
int ty = 0;
foreach (Control tCorl in this.panel1.Controls)