472,121 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

How to move a control at run time

I want to move a textbox to the same position as another combobox at run
time, but got compilation error.

I use the Location.X and Location.Y but no luck.
Nov 7 '06 #1
5 30696
Hi Alan,
use the Left and Top properties instead to change the control location.
The reason you cannot say:

myControl.Location.X = 50;

is because Location returns a Point structure, this is passed by value so a
copy is made when the value is returned from the call to the property, so you
would not be assigning to the point structure located inside the control
instance but to a temporary copy that would be lost, in effect this is not an
lvalue.

Mark.
--
http://www.markdawson.org
"Alan T" wrote:
I want to move a textbox to the same position as another combobox at run
time, but got compilation error.

I use the Location.X and Location.Y but no luck.
Nov 7 '06 #2
An alternative method is to replace the Point in Location with a new
Point, for instance the Location of another control.

textBox1.Location = comboBox1.Location;
On Tue, 07 Nov 2006 08:08:01 +0100, Mark R. Dawson
<Ma*********@discussions.microsoft.comwrote:
Hi Alan,
use the Left and Top properties instead to change the control location.
The reason you cannot say:

myControl.Location.X = 50;

is because Location returns a Point structure, this is passed by value
so a
copy is made when the value is returned from the call to the property,
so you
would not be assigning to the point structure located inside the control
instance but to a temporary copy that would be lost, in effect this is
not an
lvalue.

Mark.


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 7 '06 #3

Morten Wennevik wrote:
An alternative method is to replace the Point in Location with a new
Point, for instance the Location of another control.

textBox1.Location = comboBox1.Location;
Agreed. This is what I would do. If you have to make some modifications
to the location, say 10 pixels to the right of the combo box and 4
pixels down, use a construction like:

textBox1.Location = new Point(comboBox.Location.X + 10,
comboBox.Location.Y + 4);

or perhaps it's nicer to read:

textBox1.Location = new Point(comboBox.Left + 10, comboBox.Top + 4);

Nov 7 '06 #4
Hi Mark,

That doesn't compile, so it can't be the problem.

--
Dave Sexton

"Mark R. Dawson" <Ma*********@discussions.microsoft.comwrote in message
news:85**********************************@microsof t.com...
Hi Alan,
use the Left and Top properties instead to change the control location.
The reason you cannot say:

myControl.Location.X = 50;

is because Location returns a Point structure, this is passed by value so a
copy is made when the value is returned from the call to the property, so
you
would not be assigning to the point structure located inside the control
instance but to a temporary copy that would be lost, in effect this is not
an
lvalue.

Mark.
--
http://www.markdawson.org
"Alan T" wrote:
>I want to move a textbox to the same position as another combobox at run
time, but got compilation error.

I use the Location.X and Location.Y but no luck.

Nov 7 '06 #5
Nvm

The thread title says "run time" but the OP says "compile time"

I didn't read it thoroughly ;)

--
Dave Sexton

"Mark R. Dawson" <Ma*********@discussions.microsoft.comwrote in message
news:85**********************************@microsof t.com...
Hi Alan,
use the Left and Top properties instead to change the control location.
The reason you cannot say:

myControl.Location.X = 50;

is because Location returns a Point structure, this is passed by value so a
copy is made when the value is returned from the call to the property, so
you
would not be assigning to the point structure located inside the control
instance but to a temporary copy that would be lost, in effect this is not
an
lvalue.

Mark.
--
http://www.markdawson.org
"Alan T" wrote:
>I want to move a textbox to the same position as another combobox at run
time, but got compilation error.

I use the Location.X and Location.Y but no luck.

Nov 7 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Pedro | last post: by
1 post views Thread by Peter Wu | last post: by
8 posts views Thread by Robson Machado | last post: by
4 posts views Thread by Nancy | last post: by
reply views Thread by BrianDH | last post: by
reply views Thread by BrianDH | last post: by
reply views Thread by terminator | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.