嗨,任何人都可以告訴我如何創建一個類似於我在這裏發佈的圖片的自定義框架。框架應該根據放置在其中的按鈕進行調整。 如何使用按鈕創建自定義框架......?
上傳的圖片可能會提供更好的想法,我想創建類似的東西。那麼如何在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