开发者

How to get the Textbox location from various TableLayoutPanel ?

开发者 https://www.devze.com 2023-04-03 08:16 出处:网络
I have four (4) TableLayoutPanels. And inside them I have some TextBoxes. My intention is to display the Listview at downside of that Textbox.

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 X-Y... So how to get t开发者_开发知识库he correct location?


... its not giving proper X-Y ... 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消