tableLayoutPanel中那个单元格怎么设置大小啊

解决方案 »

  1.   


          //只能设置某行某列的高和宽吧
          tableLayoutPanel1.RowStyles[rowindex].Height = 100;
          tableLayoutPanel1.ColumnStyles[columnindex].Width = 100;
      

  2.   


          RowStyle rs = tableLayoutPanel1.RowStyles[rindex];
          rs.SizeType = SizeType.Absolute;
          rs.Height = 100;
          ColumnStyle cs = tableLayoutPanel1.ColumnStyles[cindex];
          cs.SizeType = SizeType.Absolute;
          cs.Width = 100;
      

  3.   


        /// <summary>
        /// 设置网格大小
        /// </summary>
        public virtual void _SetGridSize()
        {
          int width = this.tableLayoutPanel1.Width; //宽度
          int height = this.tableLayoutPanel1.Height;       //高度      //行数列数
          int rowcount = this.tableLayoutPanel1.RowCount;
          int columncount = this.tableLayoutPanel1.ColumnCount;      //减去网格线 宽
          if (this.tableLayoutPanel1.CellBorderStyle == TableLayoutPanelCellBorderStyle.Single)  //还有或者
          {
            width -= (columncount + 1);  //减去条线的宽度
            height -= (rowcount + 1);
          }
         
          //获取余数
          int rowremainder = height % rowcount; //余数
          int colremainder = width % columncount;      //AVG
          int rowheight = height / rowcount;
          int columnwidth = width / columncount;      //设置行高
          for (int i = 0; i < rowcount; i++)
          {
            RowStyle rs = tableLayoutPanel1.RowStyles[i];
            rs.SizeType = SizeType.Absolute;
            if (i < rowremainder)
            {
              rs.Height = rowheight + 1; //把多余的数平均一下,用float类型计算会有点问题,所以干脆用int
            }
            else
            {
              rs.Height = rowheight;
            }
          }      //设置列宽
          for (int j = 0; j < columncount; j++)
          {
            ColumnStyle cs = tableLayoutPanel1.ColumnStyles[j];
            cs.SizeType = SizeType.Absolute;
            if (j < colremainder)
            {
              cs.Width = columnwidth + 1;
            }
            else
            {
              cs.Width = columnwidth;
            }
          }
        }