public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
float fRowPercentage = 100;
float fColumnPercentage = 100;
Int32 iRows = 8;
Int32 iCols = 8;
if (iCols > 0)
fColumnPercentage = 100 / iCols;
if (iRows > 0)
fRowPercentage = 100 / iRows;
//LayoutCtrl.Dock = DockStyle.None;
LayoutCtrl.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
LayoutCtrl.ColumnCount = iCols;
LayoutCtrl.ColumnStyles.Clear();
for (int iCol = 0; iCol < iCols; iCol++)
{
LayoutCtrl.ColumnStyles.Add(new ColumnStyle(System.Windows.Forms.SizeType.Percent, fColumnPercentage));
}
LayoutCtrl.RowCount = iRows;
LayoutCtrl.RowStyles.Clear();
for (int iRow = 0; iRow < iRows; iRow++)
{
LayoutCtrl.RowStyles.Add(new RowStyle(System.Windows.Forms.SizeType.Percent, fRowPercentage));
}
LayoutCtrl.AutoSize = false;
LayoutCtrl.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
LayoutCtrl.SuspendLayout();
for (int iRow = 0; iRow < iRows; iRow++)
{
for (int iCol = 0; iCol < iCols; iCol++)
{
Button btn = new Button();
if (btn != null)
{
// Assign the property changed event.
btn.Dock = DockStyle.Fill;
LayoutCtrl.Controls.Add(btn);
}
}
}
LayoutCtrl.ResumeLayout();
LayoutCtrl.Update();
LayoutCtrl.Visible = true;
}
private void Form1_Resize(object sender, EventArgs e)
{
if (LayoutCtrl == null)
return;
LayoutCtrl.Height = this.Height - LayoutCtrl.Top;
LayoutCtrl.Width = this.Width;
LayoutCtrl.Update();
LayoutCtrl.Invalidate();
LayoutCtrl.Refresh();
}
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE