嗨,任何人都可以告诉我如何创建一个类似于我在这里发布的图片的自定义框架。框架应该根据放置在其中的按钮进行调整。 如何使用按钮创建自定义框架......?
上传的图片可能会提供更好的想法,我想创建类似的东西。那么如何在windows窗体中创建这样的框架呢?
我的代码:
私人无效的button1_Click(对象发件人,EventArgs的){
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);
}
但我不知道如何创建一个框架,并相应安排。
你到目前为止尝试过什么?您是否阅读过至少一篇关于Windows Forms的教程? –
那么,如果你还没有尝试过什么,你什么都不会做。请阅读并尝试一些关于winforms的内容,然后你就可以自己做。只是一个输入,如果考虑到其中所有控件的宽度和高度,您的框架将可调整大小。好好享受。 – Sylca
@Sylca:现在,我已经添加了代码,所以现在可以指导我PLZ ..希望你有我的问题,这只是我需要创建一个框架与按钮放置在里面,框架应该是可重新分级。 – jagadisha