• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 132
  • Last Modified:

Location Property of a Control ( X and Y)

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.
0
metro156
Asked:
metro156
  • 6
  • 6
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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.
0
 
metro156Author 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.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
metro156Author 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.
0
 
metro156Author Commented:
I am using VS 2012 .NET 4.5
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
   
    Point pt = rgv_Quote_QLines.Location;
   pt.X = 5;
   rgv_Quote_QLines.Location = pt;  // not sure if this line is necessary but showing you can assign the location to a valid point.

Open in new window

0
 
metro156Author 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.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
The question was answered.  X and Y are not read only values.
0
 
metro156Author 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.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
That's because you're doing:

rgv_Quote_Qlines.Location.X

this is wrong.

You can do:
http://www.experts-exchange.com/Programming/Microsoft_Development/Q_28498703.html#a40263898
0
 
metro156Author 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.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Correct.  And no issues, thanks for working it out :-).
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now