Position

How can i determine the position in the screen

e.g. :  we got a form (somewhere) with a panel and on that panel there's a groupbox. on that groupbox there is a button.
When you click on the button , a new form wil show right below the button

to show the new form i need the coordinates of the button on the screen

I could dril up in the hirachie until there is no parent anymore and sum al the top and left values

But i suspect there is a elegant methode to do this

Regards Remco


Answer this question

Position

  • kojot

    Tns a lot That worked

    Remco


  • Brendan Comerford

    Hi,


    Form1 nForm = new Form1();

    nForm.StartPosition = FormStartPosition.Manual;

    nForm.Left = button2.Right + this.Left;

    nForm.Top = button2.Bottom + this.Top + 15;

    nForm.ShowDialog();


     


  • Edmund Leung

    hi, this only works when the button is hosted directly on the form, not when it's hosted on for example a panel

    Remco

  • fleshi

    the framework solution goes like this (in VB):



            Dim point As New Point(Button1.Width, 0)
            point = Button1.PointToScreen(point)

            Form2.Show()
            Form2.Location = point

     



  • Robin Speed

    In .NET framework 2 you can use the PointToScreen function. I don't know if it's available in framework 1.1.

    If not you should use the ClientToScreen function of user32 API. The syntax is the following and the function does exaclty what you want. Converts coordinates of a control from the window coordinate system to the screen coordinate system:
    Declare Function ClientToScreen Lib "user32" Alias "ClientToScreen" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long


  • Position