开发者

C# - Center form based on listview coordinates?

I have a form that contains two listview controls.

When I clic开发者_开发问答k 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜