Some people here talk about Point
is a value type and you can't change its X
and Y
, that kind of explanation can confuse you much. I post this answer here to help you understand why you can't change it's Location
. That's because Location
is a Property
which returns a Structure
not a reference to an Object
, if you have a field instead, you can change that way, like this:
public class YourControl : BaseControl {
public Point Location;
}
//Then you can change the Location your way:
yourControl.Location.X = ....
However, as I said, Location
is a Property
which returns a copy of a value type (structure), like this:
public class YourControl : BaseControl {
private Point location;
public Point Location {
get {
return location;//a copy
}
set {
location = value;
}
}
}
//So when you call this:
yourControl.Location
//you will get a copy of your Location, and any changes made on this copy won't affect
//the actual structure, the compiler needs to prevent doing so.
yourControl.Location.X = ... //Should not be executed...
This is not the only case for Location
, you can find this issue in all other Properties which are value types.