Results 1 to 3 of 3

Thread: Getting the Location of a control on a form

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    London
    Posts
    63

    Getting the Location of a control on a form

    I have a textbox created in code and displayed on a form.

    I need to get the location of the control within the form.

    I'm able to get it using

    textBox.Location if the control is placed on a form.

    BUT, if the control is placed inside a GroupBox (frame) then

    textBox.Location return the location of the textBox inside the frame and not the location of the texBox compared with the form.

    any ideas how I can get the Location based on the form

    note: the my control can any be placed on the form, inside another control or inside a another control that is also inside another control, i.e. a frame in a frame.

  2. #2

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    London
    Posts
    63
    to simplify, all I really need is the Location (x,y coords) of my control relative to the form, and not relative to a frame that it is in.


  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Didn't feel like starting a new C# project, so here it is in VB...
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, _
    2.                               ByVal e As System.EventArgs) _
    3.                               Handles Button1.Click
    4.         Dim pt As Drawing.Point = Button1.Location
    5.  
    6.         pt = Button1.PointToScreen(pt)
    7.         pt = Button1.TopLevelControl.PointToClient(pt)
    8.  
    9.         MsgBox("Top:" & pt.Y & "; Left:" & pt.X)
    10.  
    11.     End Sub

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

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