int width, height;
width = this.Size.Width;
height = this.Size.Height;
width /= 3;
height /= 3;
btn_1.Size = new Size(width, height);
我試圖在用戶調整窗體大小時更改按鈕的大小和位置。如何更改按鈕的大小
我如何分配大小的按鈕?
我試圖改變分開的寬度和高度,使之。我知道我可以通過錨定來實現,但我想用純編碼來實現。
也刷新表單不起作用。我可以使用Location
屬性輕鬆設置按鈕的位置,但size屬性不起作用。我找不到區別...
以下是完整的代碼,適用於改變對象的位置,但改變大小不起作用:
private void form_counterMain_Resize(object sender, EventArgs e)
{
int width, height;
Point templocation;
templocation = new Point(0, 0);
width = this.Size.Width;
height = this.Size.Height;
width /= 3;
height /= 3;
//:::location:::
btn_1.Location = templocation;
templocation.X = width;
btn_2.Location = templocation;
templocation.X = width * 2;
btn_3.Location = templocation;
templocation.X = 0;
templocation.Y = height;
btn_4.Location = templocation;
templocation.X = width;
btn_5.Location = templocation;
templocation.X = width * 2;
btn_6.Location = templocation;
templocation.Y = height * 2;
templocation.X = 0;
btn_7.Location = templocation;
templocation.X = width;
btn_8.Location = templocation;
templocation.X = width * 2;
btn_9.Location = templocation;
//:::size:::
btn_1.Size = new Size(width, height);
this.Refresh();
您是否嘗試過設置.width和.height而不是.size? – Fosco 2010-07-09 20:25:28
另外,嘗試在編輯大小後刷新論壇。 – Meiscooldude 2010-07-09 20:26:46
@Meiscooldude,並且您可以使用Application.DoEvents()創建此刷新事件。 – 2010-07-09 20:32:19