表格布局面板出现问题 [英] Problem with Table Layout Panel

查看:87
本文介绍了表格布局面板出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在创建一个TableLayout,用户在运行时在其中设置行和列.

窗体上的初始控件是rowsTextBox,columnsTextBox,button1和tableLayoutPanel1.

我从初始程序中修改了一些代码.这是旧代码.

Hi,

I am creating a TableLayout in which the rows and columns are set by the user at runtime.

There initial controls on the form are rowsTextBox, columnsTextBox, button1 and tableLayoutPanel1.

I modified some of the code from my initial program. Here''s the old code.

private void button1_Click(object sender, EventArgs e)
 {
  tableLayoutPanel1.RowCount = int.Parse(rowsTextBox.Text);
  tableLayoutPanel1.ColumnCount = int.Parse(columnsTextBox.Text);

  for (int col = 0; col < tableLayoutPanel1.ColumnCount; col++)
  {
  for (int rows = 0; rows < tableLayoutPanel1.RowCount; rows++)
  {
   Panel p = new Panel();
   TextBox tb = new TextBox();
   Button btn = new Button();
   p.Controls.Add(tb);
   p.Controls.Add(btn);
   btn.Location = new Point(0, tb.Top + 20);
   tableLayoutPanel1.Controls.Add(p, col, rows);
  }
  }



这是同一按钮单击事件中的新代码.只是一些补充,基本代码保持不变,但是我不知道所形成的行和列的数量是不正确的. (尝试5 x5或6.x6等大于3x3)



Here''s the new code in the same button click event. Just some additions , the basic code remains the same but I dont know the number of rows and columns being formed are not correct. (try 5 x5 or 6. x6 etc. greater than 3x3 )

output.Person.Clear();
        output.Row = int.Parse(rowsTextBox.Text);
        output.Column = int.Parse(columnsTextBox.Text);
        tableLayoutPanel1.Controls.Clear();
        tableLayoutPanel1.RowCount = int.Parse(rowsTextBox.Text);
        tableLayoutPanel1.ColumnCount = int.Parse(columnsTextBox.Text);
        tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;
        for (int col = 0; col <= tableLayoutPanel1.ColumnCount - 1; col++)
        {
          for (int rows = 0; rows <= tableLayoutPanel1.RowCount - 1; rows++)
          {
            Panel p = new Panel();
            PictureBox picb = new PictureBox();
            Label lb = new Label();
            p.Controls.Add(lb);
            p.Controls.Add(picb);
            //Set the label properties            
            lb.BackColor = Color.White;
            lb.Size = new Size(88, 15);
            lb.Location = new Point(panel1.Left + 1, panel1.Top + 1);
            //Set the picture box properties            
            picb.Location=new Point(0,lb.Top + 20);
            picb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
            picb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
            picb.BackColor = Color.White;
            picb.Dock = DockStyle.Fill;                                              
            tableLayoutPanel1.Controls.Add(p, col, rows);
            p.Dock = DockStyle.Fill;            
            picb.MouseClick += pb_Click;            
            LayoutItem item = new LayoutItem()
            {
              //This assignment is new in Visual studio 2008
              ItemLabel = lb,
              ItemPcitureBox = picb,
              pnlcolor=p
            };
            m_items.Add(item);            
            Customer c = new Customer();
            c.Index = col * tableLayoutPanel1.RowCount + rows;     



截图: http://img229.imageshack.us/img229/429/captureyv.png [ ^ ]

我尝试了很多事情,但仍然困扰着这个问题.
但是,我注意到PlaceHolder(即面板)内的Form上的TableLayoutPanel并将TableLayoutPanel停靠样式设置为Fill,以便TableLayoutPanel覆盖整个表单.面板固定在顶部,左侧,底部,右侧.我认为该小组必须解决该问题.

这些行会根据表单的大小进行调整,而不是根据面板的大小进行调整(在这种情况下,该大小小于表单的大小).

就我而言,使用面板是必不可少的,因为我必须填写表格上的TableLayout.
另外,我可能是错的,因为我试图从有问题的程序中删除面板,但是单元仍然不相等.
帮助!!!



Screenshot: http://img229.imageshack.us/img229/429/captureyv.png[^]

I tried many things but still lingering with the problem.
However, I noticed that the TableLayoutPanel on the Form inside a PlaceHolder i.e. Panel and set the TableLayoutPanel dockstyle to Fill so that the TableLayoutPanel covers the whole form. Panel is anchored to Top, Left, Bottom, Right. I think this panel has to do something with the problem.

The rows adjust themselves according to the size of the Form and not to the size of the Panel (which in this case is less than the size of the form).

In my case, it was essential to use the Panel since I had to Fill the TableLayout on the Form.
Also, I may be wrong since I tried to remove the Panel from the problematic program but the cells still weren''t becoming equal.
Please HELP!!!

推荐答案

尝试将面板的"AutoSize"属性设置为"true",将AutoSizeingMode设置为"GrowAndShrink" ".希望这会有所帮助.
问候,
Kemo
try to setting the panels'' AutoSize property to ''true'' and AutoSizeingMode to ''GrowAndShrink''. Hope this will help.
Regards,
Kemo


这篇关于表格布局面板出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆