FormStartPosition.CenterParent does not work

前端 未结 13 974
独厮守ぢ
独厮守ぢ 2021-01-01 08:57

In the following code, only the second method works for me (.NET 4.0). FormStartPosition.CenterParent does not center the child form over its parent. Why?

13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-01 09:50

    Small Change to JYelton's answer

    Form2_Load(object sender, EventArgs e)
    {
        if (Owner != null && Parent == null && StartPosition == FormStartPosition.CenterParent)
        Location = new Point(Owner.Location.X + Owner.Width / 2 - Width / 2,
            Owner.Location.Y + Owner.Height / 2 - Height / 2);
    }
    

提交回复
热议问题