Hi Guys,
I am trying to create a re-sizable windows that when ever a user click a button a groupBox appear at windows ,eventually the Height of the form will increase and when the user want to hide the groupbox the windows will back t its regular size.
I have a winForm as MyForm which has a size of (300,300) and I want to make it as (300,400) when ever the "btnShow" is clicked by users.
I tried to set the Size property which was not available for MyForm.

void btnHideClick(object sender, EventArgs e)
		{
		gBox.Visible = false;
                //MyForm.Size  ??????	
		}
void btnShowClick(object sender, EventArgs e)
		{
		gBox.Visible = true;
	        //MyForm.Siz??????	
		}

Thanks

this.Size.Height = 400;

Hi Momerath
Thanks for your help but I am getting error for this.
I already try this but didn't go through!
This the Error message I am getting on:

Cannot modify the return value of 'System.Windows.Forms.Forms.Size' Because is not a Variable(CS1612)

Thanks again

Try this, properties do things like that (you can't modify a property of a property directly)

Size s = this.Size;
s.Height = s.Height + 100
this.Size = s;

Size is a read only property. Use Width and Height directly, Size is just a helper property if you need them as a Size object.

Form1 f = new Form1();
 f.Height = 400;

Perfect!
You are a rock! this is working.

Size s = this.Size;
s.Height = s.Height + 100
this.Size = s;

I still do not understand how!? but it is resizing the Form.

Thanks

Size is a struct - it comes from System.Drawing namespace. You create a new instance of it. Struct size has its own properties, like Height, Widht ... to which you assign new value like Momerath did).
But I would do it even shorter:

Size s = this.Height + 100;
this.Size = s;

Hi
when ever i am using the last modified code by you

Size s = this.Height + 100;
this.Size = s;

I am getting this warning
Cannot implicitly convert type 'int' to 'System.Drawing.Size'

Did it work fine for you?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.