简体   繁体   中英

How to get the Textbox location from various TableLayoutPanel ?

I have four (4) TableLayoutPanels. And inside them I have some TextBoxes. My intention is to display the Listview at downside of that Textbox. Hence when I try to get the location of textbox which is inside the tablelayout panel, its not giving proper XY... So how to get the correct location?

... its not giving proper XY ... Not really :

You can have multiple solutions :

  1. Using the Location property which provides two values X and Y, the Location property gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container :

Location Property :

int xLocation = textBox1.Location.X;
int yLocation = textBox1.Location.Y;
  1. Using the Left , Top , Right , Bottom properties : they actually get the distance, in pixels, between the left (or top, right, bottom respectively) edge of the control and the top edge of its container's client area :

Left, Top, Right Bottom :

int leftLocation = textBox1.Left;
int topLocation = textBox1.Top;
int rightLocation = textBox1.Right;
int bottomLocation = textBox1.Bottom;

If you check the values of all these lines, you will find that left and top values are identical to the X and Y values of the Location property.

All these properties are there due to the inheritance from the Control object, hence you will find them on any control deriving from that.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM