I want to make a resizable menu on the top of my main Windows form. I added a TableLayoutPanel and set its Dock property to Top. There are equal 4 columns on this TableLayoutPanel. I have added a button on every columns and set their Dock property to Fill. When I maximize the form, my menu becomes wider and fits to form's width. That is what I want for now. However, when I decrease(not minimized) the width of form, buttons started to disappear from the left. I expect to autosize itself when form's width decrease. How can I prevent this? Any suggestions?
Asked
Active
Viewed 137 times
0
-
You didn't configure the columns in the TLP correctly. – Hans Passant Jan 13 '14 at 16:08
-
@HansPassant columns are on their default value which is: autosize – cihadakt Jan 14 '14 at 07:05
1 Answers
0
I was able to reproduce this behavior quite quickly in VS2013 targeting the .Net 4.0 framework. It appears as though the last column is the one affected by the autosizing process. I set the columns to be absolute (20 pixels) and then used a dynamic calculation to determine the percentage of the screen that the column should consume. Any time you add/remove a column, you would need to call the SetColumnSize()
method.
public Form1()
{
InitializeComponent();
SetColumnSize();
}
private void SetColumnSize()
{
float colPercent = 100 / this.tableLayoutPanel1.ColumnCount;
this.tableLayoutPanel1.ColumnStyles.Clear();
for (int i = 0; i < this.tableLayoutPanel1.ColumnCount; i++)
{
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, colPercent));
}
}

AWinkle
- 673
- 8
- 18