private void ShowSeat()
        {
            //Button lbl = new Button();
            Label lbl = new Label();
            for (int i = 0; i < seatRow; i++)
            {
                for (int j = 0; j < seatCol; j++)
                {
                    lbl.Name = "lbl" + (i+1) + "-" +( j+1);
                    lbl.Click += new EventHandler(lbl_Click);
                    lbl.BackColor = Color.Yellow;
                    lbl.AutoSize = false;
                    lbl.Location = new System.Drawing.Point(59, 60);
                    lbl.Size = new System.Drawing.Size(50, 25);
                    lbl.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((byte)(134)));
                    lbl.Text = lbl.Name = "lbl" + (i + 1) + "-" + (j + 1);
                    lbl.Location = new System.Drawing.Point(60 + (i * 90), 60 + (j * 60));
                    this.tpSeatList.Controls.Add(lbl);
                    
                }
            }
        }然后直接在 主窗体调用 

解决方案 »

  1.   

    这几天也在学这个。。
    seatRow 和 seatCol 的初始化赋值没问题吗
    如果直接调用这个showseat函数   seatrow和seatcol的值没做传递啊
      

  2.   

    lbl.Location = new System.Drawing.Point(60 + (i * 90), 60 + (j * 60));这句有问题,注释掉就可以显示了。
      

  3.   


    超出界限了,肯定是你的 坐标 不太合理导致的,像楼上说的一样,先把 lbl.Location = new System.Drawing.Point(60 + (i * 90), 60 + (j * 60)); 这行代码 注释掉先,看看虾米 情况,实在不行再改动 坐标的 值。
      

  4.   

    Label lbl = new Label();
    我觉得这句话应该在最内层for循环内,不然一个循环下来只对一个lbl对象进行操作。
      

  5.   


    举个例子         Label lbl = null;
            public void AddLabel()
            {
                
                for (int i = 1; i <= 7; i++)
                {
                    for (int j = 1; j <= 7; j++)
                    {
                        lbl = new Label();           
                        lbl.Width = 40;
                        lbl.Height = 25;
                        lbl.Text = i + "-" + j;
                        lbl.TextAlign = ContentAlignment.MiddleCenter;
                        lbl.BackColor = Color.Red;
                        lbl.Location = new Point((70* i), (j * 30));
                        lbl.Top -= 15;
                        this.tabPage1.Controls.Add(lbl);                    //添加Label标签
                           lbl.Click += new EventHandler(lbl_Click);
                        Seat s = new Seat { SeatNum = lbl.Text, Color = lbl.BackColor };
                        labels.Add(lbl.Text, lbl);
                        c.Seats.Add(s.SeatNum, s);
                        
                    }
                }
            }
      

  6.   


    看看你要吧Label标签显示在哪里,看看那个控件的大小,然后根据那个长和宽来计算。