[RESOLVED] [2005] Find out all location co-ordinates of control
Is this just a simple matter of basic math using the location and size properties?
I take it location gives the (x, y) of the top left corner of say a picture box that I've drawn on the screen. To work out bottom left do I just use the height property and subtract from the Y co-ordinate to get the bottom left and do similar using width and height to work out top and bottom right corners?
Or is there more to it?
S
Re: [2005] Find out all location co-ordinates of control
The bottom left coords will be (x, y + height) and the top right will be (x+width, y).
EDIT: The coordinates of the top right corner of the screen are (0,0).
Hope this helps
:thumb:
Re: [2005] Find out all location co-ordinates of control
All controls have Location, Size, Width, Height, Top, Left, Bottom and Right properties. The following are true:
Location.X = Left
Location.Y = Top
Size.Width = Width
Size.Height = Height
Bottom = Top + Height
Right = Left + Width
Location, Size, Top, Left, Height and Width can all be set at run time. Location.X, Location.Y, Size.Height, Size.Width, Bottom and Right cannot.
The Location, Top, Bottom, Left and Right properties are in relation to the top, left corner of the control's parent. You can convert a point in a controls coordinate system to screen coordinates and back using that control's PointToScreen and PointToClient methods. For instance, if you place a Panel on a form the following code will give you the coordinates of the Panel relative to the top, left corner of the screen:
VB Code:
Dim pt As Point = Me.PointToScreen(Me.Panel1)
Re: [2005] Find out all location co-ordinates of control
Thanks guys, I've got all the info I need now. I came across the PointToScreen option just as you posted JMC.
It came up with a different value to my location value for my picturebox but realised they are measured in relation to different things.
Cheers for the useful info.
EDIT: JMC I think it needs to be
VB Code:
Dim pt As Point = Me.PointToScreen(Me.Panel1.Location)
Re: [2005] Find out all location co-ordinates of control
Quote:
Originally Posted by stimbo
Thanks guys, I've got all the info I need now. I came across the PointToScreen option just as you posted JMC.
It came up with a different value to my location value for my picturebox but realised they are measured in relation to different things.
Cheers for the useful info.
EDIT: JMC I think it needs to be
VB Code:
Dim pt As Point = Me.PointToScreen(Me.Panel1.Location)
I think someone deleted the ".Location" from my post just to make me look bad. :blush: ;)
Re: [RESOLVED] [2005] Find out all location co-ordinates of control
The scoundrels! They do it to me all the time. :p