ranjit powar
ranjit powar

Reputation: 104

Change width of a Windows Forms form at runtime

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?

Upvotes: 1

Views: 12285

Answers (3)

Katu
Katu

Reputation: 701

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

Upvotes: 3

John Smith
John Smith

Reputation: 502

form.Size = new Size(form.Size.Width + 100, form.Size.Height);

Upvotes: 2

prospector
prospector

Reputation: 3469

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

Form1.ActiveForm.Width += 100;

Upvotes: 0

Related Questions