Click to See Complete Forum and Search --> : Help with a variable error message...


AMON
March 17th, 2003, 05:40 PM
I'm getting the following error message, and can't figure out why:

C:\CPP\MyTestApp\MyTestApp\FormMain.cs(118): Cannot modify the return value of 'System.Windows.Forms.Control.Location' because it is not a variable

Here is the line of code it refers to:

this.Location.X = Convert.ToInt32(ReadXMLConfigFile ("WindowLocationX"));

Any idea why "this.Location.X" is not a variable, when it takes an INT?

Thanks! :)
- Adrian

phirestalker
March 17th, 2003, 06:11 PM
System.Windows.Form.Location has to be assigned a Point type, and the X and Y property of that point type in Location cannot be modified directly. so just creat a Point and assign it the values from config file then

Point p = new Point(x,y);

this.Location = p;

pareshgh
March 17th, 2003, 06:15 PM
the reason is X and Y of location is a property. it needs the Point object.

for example

this.Location = new Point(100,100);

-Paresh

wolfofthenorth
March 17th, 2003, 08:49 PM
You could also use the Left and/or Top property, instead of location.

pareshgh
March 18th, 2003, 11:30 AM
in fact both are same in the sense that when you assign X,Y of Location
and Left & Top of control. both are property. in location you can set at a time and give a point. where as Left and Top would be considered as a 2 diff. statements

Paresh