views:

37

answers:

1

I have a form that contains two listview controls.

When I click on each listview another smaller form will appear.

How do I get the smaller form to center on the calling listview control?

I think it has something to with the SetBounds but I am not sure.

+2  A: 

Use this function:

static void CenterForm(Form f, Control c)
{
    f.StartPosition = FormStartPosition.Manual;
    var rc = c.PointToScreen(Point.Empty);
    f.Location = new Point(rc.X + (c.Width - f.Width) / 2,
                           rc.Y + (c.Height - f.Height) / 2);
}

f = your smaller form, c = your listview.

max
Thanks @max - works really well.
John M