Row Autosize property not working of Table Layout?

流过昼夜 提交于 2019-12-13 11:36:06

问题


I am working on a windows application, in which i am using a table layout panel, in this table layout i have created 5 rows and that is autosize, now dynamically i am adding 4 radio buttons and text for radio button is a bit long but the problem is it is behaving like absolute and not showing the full text.

I am adding radio button like this-

       for (int i = 0; i < 4; i++)
        {
            rbtn1 = new RadioButton();
            rbtn1.Name = "rbtn" + (i + 1);
            rbtn1.Text = "A jogger running at 9 kmph alongside a railway track in 280 metres ahead of the engine of a 120 metres long train running at 45 kmph in the same direction. In how much time will the train pass the jogger?";//ansList[i].ToString();
            rbtn1.Dock = DockStyle.Fill;
            rbtn1.Font = new Font("Verdana", 10);
            tableLayoutExamPanel.Controls.Add(rbtn1, 1, i + 8);
        } 

I am working on this from last 10 hours.

Need help, Thanks a lot.


回答1:


I realise this is an old question, however:

  1. Set the dock style of each RadioButton to DockStyle.None
  2. Set AutoSize = True for each RadioButton.

Autosize won't work if you have a dock style set. Make sure you the above is true for each child control on the table.




回答2:


Try setting the radio buttons autosize property to true.

And remember that a control in a TableLayoutPanel cell always shrinks to fit in the cell until its MinimumSize is reached.

P.S. You could also try setting the AutoSizeMode property to GrowOnly.

See MSDN for more info

EDIT: try this...

.RowStyles.Clear();
.RowStyles.Add(new RowStyle(SizeType.AutoSize));


来源:https://stackoverflow.com/questions/16536889/row-autosize-property-not-working-of-table-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!