/// <summary>
/// 把按钮按照行数分割排列
/// </summary>
/// <param name="ControlArry">按钮集合</param>
/// <param name="control_parent">父容器</param>
/// <param name="RowCount">每一行数量</param>
/// <param name="ControlSize">控件大小</param>
/// <param name="pad">间隔大小</param>
private void ControlToControlResize(Control[] ControlArry, Control control_parent, int RowCount, Size? ControlSize, Padding pad)
{
//计算按钮相关信息
control_parent.Controls.Clear();
//列数
int yCount = ; int xCount = RowCount;
if (ControlArry.Length < RowCount) //定义一列展示的数量大于总控件
{
yCount = ;
}
else
{
yCount = ControlArry.Length % RowCount == ? ControlArry.Length / RowCount : ControlArry.Length / RowCount + ;
}
Padding ParentsPadding = control_parent.Padding;
Size btnSize = new System.Drawing.Size();
if (ControlSize != null)
{
btnSize = (Size)ControlSize;
}
else
{
btnSize.Width = Convert.ToInt32(Math.Floor(((double)control_parent.Width - (ParentsPadding.Left + ParentsPadding.Right)) / RowCount));
btnSize.Height = Convert.ToInt32(Math.Floor(((double)control_parent.Height - (ParentsPadding.Top + ParentsPadding.Bottom)) / yCount));
}
int index = ;
for (int i = ; i < yCount; i++)//行数
{
for (int j = ; j < xCount; j++)//一行多少个
{
if (index >= ControlArry.Length)
{
break;
}
else
{
ControlArry[index].Size = btnSize;
ControlArry[index].Padding = pad;
ControlArry[index].Location = new Point(j * btnSize.Width + ParentsPadding.Left, i * btnSize.Height + ParentsPadding.Top);
index++;
}
}
}
control_parent.Controls.AddRange(ControlArry);
}