tags:

views:

26

answers:

1

Hi everyone. Im trying to integrate a toolwindow in a Winforms application, it will be a tiny floating window to display element details in a listbox. What I need is pop the window in a relative position to the control that triggers the action, so here is the thing: the Location property gives me the relative position of the control from its container (the main form in this case) so this is the workaround im using:

    public void Show(kTextBox source)
    {

        Point absCoord = source.PointToScreen(source.Location);
        this.Location = this.PointToClient(absCoord);
        base.Show();

    }

Basically this is: get the absolute control position and set this position (previously converted into owner relative) to the toolwindow. I think it should work just fine but is missing for a certain degree, and it varies depending what control i use. Its kinda confusing. Been there anyone?? Thanks in advance.

+1  A: 

What happens if you try the following:

public void Show(kTextBox source)
{
    Point control_origin = source.PointToScreen(new Point(0, 0));
    this.Location = new Point(control_origin.X, control_origin.Y);
    base.Show();
}
SwDevMan81
Yep, you got it! Looks like I had a poor understanding of the POintToScreen/Client functions.. thanks a lot!
Enmanuel