BUG: In Size.Height or Size.Width in Controls

  • Thread starter Thread starter BUG
  • Start date Start date
B

BUG

Hi,

MSDN docs specify the Height or Width part of the Size
property as settable yet Size is a valuetype (struct in
C#) and .Size.Height and .Size.Width cannot be Set, just
GET is allowed. Unless you set Size to a new instance.

Why does MSDN say that it is a set property when its only
a get?

Am I incorrect in understanding this or are they?

Thanks
 
Hi,
You got it wrong. Here what MSDN says
"Because the Size class is a value type (Structure in Visual Basic, struct
in C#), it is returned by value, meaning accessing the property returns a
copy of the size of the control. So, adjusting the Width or Height
properties of the Size object returned from this property will not affect
the Width or Height of the control. To adjust the Width or Height of the
control, you must set the control's Width or Height property, or set the
Size property with a new Size object."

Control class has designated Height and Width properties, which can be used
to set only one of the dimentions. You can set the Size property as whole as
well.

HTH

B\rgds
100
 
Yes but if you look more CLOSELY, you will see that .Size.Height = a Set
property yet its NOT. Its a get only, if you want to set it you either set
..Size with a new object or you set .Height further up the class.

Go look at the .Size.Height property, its labled as a get and set when
infact its just a get. You try this then.


form.Size.Height = 100;

You cant. because its not a set property yet its stated that it is.
 
Hi anonimous,
Control.Size return a value of Size type (structure). Size type has Height
property which is settable and you can set it. This is legal and it works as
it suppose to. The problem is that you change the .Height of the local copy
as long as the Size is a value type. That's why there is such a remark in
MSDN warning not to do
form.Size.Height = 100, but do form.Height = 100 instead.
Or
Size formSize = form.Size;
formSize.Height = 100;
form.Size = formSize;


This is not a bug it is how the value types work.

B\rgds
100
 
Back
Top