开发者

C# - Center form based on listview coordinates?

开发者 https://www.devze.com 2023-01-02 02:17 出处:网络
I have a form that contains two listview controls. When I clic开发者_开发问答k on each listview another smaller form will appear.

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

精彩评论

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

关注公众号