John,
The reason that this doesn't work is because Location is of type Point,
which is a value type. When you return value types from properties or
methods (through the return value, not ref parameters), a copy is made and
returned to you.
That being said, when you do this:
rb.Location.X= 67;
You are setting the X property/field on a copy returned to you. To
perform this operation, you would need to do this:
// Store the location.
Point temp = rb.Location;
// Set the X value.
temp.X = 67;
// Set the location back.
rb.Location = temp;
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
<jo************@googlemail.com> wrote in message
news:11********************@z14g2000cwz.googlegrou ps.com...
am trying to add controls (e.g. radio buttons, group boxes) to a
windows form in a method which I call from the constructor.
However, when I do things like;
RadioButton rb= new RadioButton();
...
rb.Location.X= 67;
this.Controls.Add(rb); // this is the Windows Form instance
I am told that;
"Cannot modify the return value of
'System.Window.Forms.Control.Locatoin' because it is not a variable"
I have tried to use CreateControl() but it doesn't seem to have any
effect.
If anyone knows how to do this please help asap
John