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