1

I want to change width of a Windows Forms form at runtime. I am also executing SuspendLayout and resumelayout method, but it doesn't work.

  System.Windows.Forms.Control form = this.currentForm;
  form.SuspendLayout();
  form.Width = form.Width + 100;
  form.ResumeLayout();

How can I make it work?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ranjit powar
  • 104
  • 2
  • 2
  • 10

3 Answers3

3

Set the size of form like this

Form1.Size = new System.Drawing.Size(100, 100);

or

Form1.Size = new System.Drawing.Size(100, Form1.Size.Height);

Once the Size has been defined, you can change Form size like this

Form1.Width += 200;

MSDN - Resizing Windows Forms

Katu
  • 701
  • 1
  • 8
  • 22
2
form.Size = new Size(form.Size.Width + 100, form.Size.Height);
John Smith
  • 496
  • 1
  • 6
  • 20
0

Obviously, replace "Form1" with your form name. It's this easy:

Form1.ActiveForm.Width += 100;
prospector
  • 3,389
  • 1
  • 23
  • 40
  • 1
    Are you sure it's different than `form.Width = form.Width + 100;` ? .. and how if it's not activeform ? – matzone Jul 12 '13 at 07:33