I have a method that returns a value, and I want this value to be the new location of a label in a windows form application. but I'm being told that a label's location is not a variable. objectA is the name of the label.
objectA.Location.X = (int)A.position;
objectA.Refresh();
how do I do this?
You can only set properties of structs if you have a direct reference to that struct:
Location is no a variable, just a public Property. Changing variables through properties is a bady idea unless you have events that update the parent.
This works to me
You even do not need to call Refresh or SuspendLayout etc.
so this should help you
the Location property is of type Point, which is a value type. Therefore, the property returns a copy of the location value, so setting X on this copy would have no effect on the label. The compiler sees that and generates an error so that you can fix it. You can do that instead :
(the call to Refresh is useless)
Use the
Left
property to change X coordinate of aLabel