Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Find out all location co-ordinates of control

  1. #1

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Resolved [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
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  2. #2
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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
    Last edited by Kimmy4; Jan 16th, 2007 at 07:36 AM.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Dim pt As Point = Me.PointToScreen(Me.Panel1)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    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:
    1. Dim pt As Point = Me.PointToScreen(Me.Panel1.Location)
    Last edited by stimbo; Jan 16th, 2007 at 09:07 AM.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Dim pt As Point = Me.PointToScreen(Me.Panel1.Location)
    I think someone deleted the ".Location" from my post just to make me look bad.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [RESOLVED] [2005] Find out all location co-ordinates of control

    The scoundrels! They do it to me all the time.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width