请问在文本框中输入行列,点击按钮怎么实现与输入相一致的行列label控件? 我写的代码只把
最后一个labl输出来了,前面的怎么不循环显示呢?
 public partial class Form1 : Form
    {
        Label lbl = new Label();
        
        public Form1()
        {
            lbl.Parent = this;
                        InitializeComponent();
        }        private void btnRun_MouseClick(object sender, MouseEventArgs e)
        {
                       
            int k = Convert.ToInt32(txtRows.Text);
            int y = Convert.ToInt32(txtCols.Text);
            for (int i = 1; i <= k; i++)
            {
                for (int j = 1; j <= y; j++)
                {
                    //Console.Write(i + "-" + j + "\t");
                                      
                    lbl.Text = i + "-" + j;
                    
                    lbl.Location = new Point(e.X, e.Y);
                    lbl.BackColor = Color.Yellow;
                    this.groupBox1.Controls.Add(lbl);
                }
            }        }
    }

 

解决方案 »

  1.   


    for (int i = 1; i <= k; i++) 

       for (int j = 1; j <= y; j++) 
       {     
                        Label lbl = new Label();     
                        lbl.Text = i + "-" + j; 
                        lbl.Location = new Point(e.X+i, e.Y+j); 
                        lbl.BackColor = Color.Yellow; 
                        this.groupBox1.Controls.Add(lbl); 
                    } 
                } 
     
      

  2.   


      主要是Location  的位置始终没改变吧!
      

  3.   

    刚才已经有人帮忙解决了,谢谢大家。
    代码如下:
    int k = Convert.ToInt32(txtRows.Text);
                int y = Convert.ToInt32(txtCols.Text);
                int px = 5;    //加了两个改变labl坐标的变量,你是一下效果 
                int py = 10;
                for (int i = 1; i <= k; i++)
                {
                    py = 10;
                    for (int j = 1; j <= y; j++)
                    {
                        // Console.Write(i + "-" + j + "\t"); 
                        Label lbl = new Label();
                        lbl.Text = i + "-" + j;
                        lbl.Location = new Point(px, py);
                        py += 60;
                        lbl.BackColor = Color.Yellow;
                        this.groupBox1.Controls.Add(lbl);
                    }
                    px += 150;
                }