重新排列容器中的按钮,效果显示如图:
窗口大小改变后:
代码:
/// <summary>
/// 重新排列控件中的按钮
/// </summary>
private void arrangeButtons()
{
int x = 0, y = 0;
TabPage tbs = (TabPage)tabControls.GetControl(tabControls.SelectedIndex);
int i = tbs.Controls.Count - 1;
foreach (Button buttons in tbs.Controls)
{
buttons.Location = new Point(x, y);
x += buttons.Width + 5;
if (x + buttons.Width > tabControls.Width)
{
x = 0;
y += buttons.Height + 5;
}
}
}
//控件大小改变,重新排列按钮
private void tabControls_SizeChanged(object sender, EventArgs e)
{
arrangeButtons();
}