int width, height;
width = this.Size.Width;
height = this.Size.Height;
width /= 3;
height /= 3;
btn_1.Size = new Size(width, height);
I am trying to make a button’s size and location change when the user resizes a form.
How can I assigning a size to a button?
I tried to make it with changing width and height separately. I know that I can make it by anchoring it, but I would like to make it with pure coding.
Also refreshing the form did not work. I can set the locations of buttons easily with the Location property, but the size property does not work. I couldn’t find the difference…
Here is the full code which works for changing the positions of objects, but does not work for changing the 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();
I couldn’t manage to find it out, why it does not change it with my code while it works with Jamie’s code. But instead of working on that, i created 9 buttons with pure code. So it gave me ability to change every property.
I don’t know if someone needs the code, i just pasted.