嗨,谁能告诉我如何创建一个类似于我在这里发布的图片的定制框架。框架应根据放置在其中的按钮调整大小。
上传的图片可能会提供更好的主意,我想创建类似的东西。那么如何在windows窗体中创建这样的框架呢?
我的代码:
私人无效按钮1_Click(对象发送者,EventArgs e){
int start_x = Convert.ToInt32(textbox1.Text);
int start_y = Convert.ToInt32(textbox2.Text);
//Clear out the existing controls, we are generating a new table layout
tableLayoutPanel1.Controls.Clear();
//Clear out the existing row and column styles
tableLayoutPanel1.ColumnStyles.Clear();
tableLayoutPanel1.RowStyles.Clear();
//Now we will generate the table, setting up the row and column counts first
tableLayoutPanel1.ColumnCount = start_x;
tableLayoutPanel1.RowCount = start_y;
for (int x = 0; x < start_x; x++)
{
//First add a column
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
for (int y = 0; y < start_y; y++)
{
//Next, add a row. Only do this when once, when creating the first column
if (x == 0)
{
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
}
//Create the control, in this case we will add a button
Button cmd = new Button();
cmd.Width = 120;
cmd.Height = 60;
cmd.BackColor = Color.LightGreen;
cmd.FlatStyle = FlatStyle.Popup;
cmd.Text = string.Format("ds");
cmd.Click += new EventHandler(this.btnDynamicButton_Click);
//Finally, add the control to the correct location in the table
tableLayoutPanel1.Controls.Add(cmd, x, y);
}
但我不知道如何创建该框架并相应地安排它。