We help IT Professionals succeed at work.

Location Property of a Control ( X and Y)

191 Views
Last Modified: 2014-09-16
I am working with a form that has  3 Panels and 1 GridView. During the running of my program I shift the panels and Grid  positions using the Top and Bottom properties.

What I am finding that the GridView will have different Location X and Y values after I run the program and view the Location X and Y properties in the design properties window.
How could that happen? I thought Location X and Y values are readonly values.
Comment
Watch Question

Kyle AbrahamsSenior .Net Developer
CERTIFIED EXPERT

Commented:
Windows or ASP.Net?

For a windows application you can set the location.X

for a asp.net application you can adjust the style via a margin or set the positioning to absolute.
Lawrence AverySystem Developer

Author

Commented:
This is a windows application. I thought Location.X and Location.Y are not variables.

 In other words, by using say GridView.Left or GridView.Top you can change the positioning of the control during runtime but the Location X and Y always contain the same values that were established during design time.
Kyle AbrahamsSenior .Net Developer
CERTIFIED EXPERT

Commented:
You can use either.

If you type in gridView.Location.X in the tool tip you'll see gets or sets . . . at least that's how it is for me - running .net 4.0 in VS 2010.
Lawrence AverySystem Developer

Author

Commented:
Here is my code:

        private void rcp_QHdr_Info_Collapsed(object sender, EventArgs e)
        {
            // Need to position Grid Lines upward
            rgv_Quote_QLines.Left = rcp_QHdr_Info.Left;
            rgv_Quote_QLines.Top = rcp_QHdr_Info.Bottom + 60;
            rgv_Quote_QLines.Location.X = 5;

        }
When I compile or even hold my mouse pointer over the code (rgv_Quote_QLines.Location) - it indicates
Cannot modify the return value of 'System.Windows.Control.Location' because it is not a variable.
Lawrence AverySystem Developer

Author

Commented:
I am using VS 2012 .NET 4.5
Senior .Net Developer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Lawrence AverySystem Developer

Author

Commented:
I've requested that this question be deleted for the following reason:

I changed my code to get around issue for now. Will revisit the issue when time permits and resubmit the question.
Kyle AbrahamsSenior .Net Developer
CERTIFIED EXPERT

Commented:
The question was answered.  X and Y are not read only values.
Lawrence AverySystem Developer

Author

Commented:
I don't believe the answer above is  true. You cannot change Location.X or Y in  in VS2012.
When I compile or even hold my mouse pointer over the code (rgv_Quote_QLines.Location) - it indicates
 Cannot modify the return value of 'System.Windows.Control.Location' because it is not a variable.
Kyle AbrahamsSenior .Net Developer
CERTIFIED EXPERT

Commented:
That's because you're doing:

rgv_Quote_Qlines.Location.X

this is wrong.

You can do:
https://www.experts-exchange.com/Programming/Microsoft_Development/Q_28498703.html#a40263898
Lawrence AverySystem Developer

Author

Commented:
Oh Ok. What you are saying is that you cannot directly assign X or Y but you can assign it by using a Point class type.
Alright. Sorry I missed that.
Kyle AbrahamsSenior .Net Developer
CERTIFIED EXPERT

Commented:
Correct.  And no issues, thanks for working it out :-).

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.