A: 

You can't directly change the Size.Width property on a UserControl, because the Size property is a value type, so changing its width would essentially be overwriting the entire Size property. Instead, controls in WinForms provide their own Width and Height properties, so this code should work:

grdNameValueProperties.Width = this.Width - 8;
grdNameValueProperties.Height = this.Height - 8;

Having said that, I agree with @recursive's comment that you should probably just use the UserControl's Anchor property to make it "automatically" resize.

Matt Hamilton
@Matt: Thanks... I did get rid of new Size() assignments. I still have the same problem: I can make the form bigger but not smaller :(
Vyas Bharghava
Which Resize event are you catching? The event on a control on which the UserControl sits? Can you catch the form's Resize event instead?
Matt Hamilton
A: 
grdNameValueProperties.Size.Width = this.Width - 8;
grdNameValueProperties.Size.Height = this.Height -8;

That code gives the error because Size is a value type, not a reference type. Reading this http://www.yoda.arachsys.com/csharp/parameters.html may help explain the difference between value types and reference types.

Brian Ensink
+1  A: 

As recursive commented, you should just use the Anchor property.

The error occurse because the Size property exposes a struct and not a reference type. The Size property returns a copy of the size object of the control. Writing to the properties Width and Hight of this copy makes no sense because it is just a temporary copy and not backed by memory anywhere.

Daniel Brückner
@danbruc: It's not the first time I've been SOOO dumb. Thanks anyway for the refresher :)
Vyas Bharghava
A: 

For the first portion -

First off, I'd recommend using the Anchor property on UserControl instead of trying to size this yourself. It works very simply, and very reliably, for handling window resizing.

If you want to do this, you should probably look at chaining off this.ClientSize instead of this.Height and this.Width. You're probably setting your control too large, and that's unachoring the panel or other thing you're sitting on, which causes all sorts of issues.

The second part is due to the fact that gridNameValue Properties.Size.Width is a member of a struct.

When you call gridNameValueProperties.Size, you're returning a Size struct, then trying to set the Width on the returned struct (not the original). This is why you need to set the entire Size valuetype in one shot. Creating a new Size() and setting it to gridNameValueProperties.Size is the only way to make that work.

Reed Copsey
@Reed: The size does change. UserControl and its child controls do become bigger if I resize the form (make it bigger, that is). The form wouldn't let me make it smaller though.
Vyas Bharghava
Do you have anything else on your form other than the UserControl? If there is another container in the form that the user control is in, and you set the user control "too large" for hte client area, I've seen this behavior. That's why I suggested changing to ClientSize.
Reed Copsey
+1  A: 

Currently, I'm able to make the zoom form bigger with the above code but not smaller.

Some controls have a MinSize (or similar) property on them. Do you have any of those set such that you can't resize smaller?

JP Alioto
@JP: Checked that... Doesn't seem to be the issue... Thanks
Vyas Bharghava