why the heck isn't this working?

J

jayderk

foreach(Control objControl in this.Controls)
{
System.Diagnostics.Debug.WriteLine("Controls type:" +
objControl.GetType().ToString());
if(objControl is TextBox || objControl is PictureBox)
{
objControl.Location.Y = (objControl.Location.Y - 24);
}
}

here is the error message, I should work cause you can get or set the Y
value?
this section is to move controls up if it is PocketPC platform. Any
suggestions?

C:\dev\CE\Csharp\frmMain.cs(82): Cannot modify the return value of
'System.Windows.Forms.Control.Location' because it is not a variable
 
J

jayderk

this fixed it.
objControl.Location = new System.Drawing.Point(objControl.Location.X,
(objControl.Location.Y - 24));
 
J

Jon Skeet [C# MVP]

jayderk said:
foreach(Control objControl in this.Controls)
{
System.Diagnostics.Debug.WriteLine("Controls type:" +
objControl.GetType().ToString());
if(objControl is TextBox || objControl is PictureBox)
{
objControl.Location.Y = (objControl.Location.Y - 24);
}
}

here is the error message, I should work cause you can get or set the Y
value?
this section is to move controls up if it is PocketPC platform. Any
suggestions?

C:\dev\CE\Csharp\frmMain.cs(82): Cannot modify the return value of
'System.Windows.Forms.Control.Location' because it is not a variable

No, it shouldn't work, because the C# specs say it shouldn't. Location
is a property, and you can't set a property or indexer on a value type
instance unless the expression is a variable.

See section 14.13.1 for more information.

This is a good thing though - if you *could* assign a value to the
property, it would effectively be a no-op. The Location property would
return a copy of the form's location, you'd modify the copy, and then
it would go out of scope. No change the form's location.

What you need to do is:

Point p = objControl.Location;
p.Y = p.Y-24;
objControl.Location = p;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top