Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change a button's size
    text
    copied!<pre><code>int width, height; width = this.Size.Width; height = this.Size.Height; width /= 3; height /= 3; btn_1.Size = new Size(width, height); </code></pre> <p>I am trying to make a button's size and location change when the user resizes a form.</p> <p>How can I assigning a size to a button?</p> <p>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.<br> Also refreshing the form did not work. I can set the locations of buttons easily with the <code>Location</code> property, but the size property does not work. I couldn't find the difference...</p> <p>Here is the full code which works for changing the positions of objects, but does not work for changing the size:</p> <pre><code>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(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload