FormStartPosition.CenterParent does not work

前端 未结 13 973
独厮守ぢ
独厮守ぢ 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 10:04

    An old question, I know, but I had the same issue but for a different reason.

    The Form I was opening had an overridden OnLoad method:

    protected override void OnLoad(EventArgs e)
    {
       //... etc.
    }
    

    but was not calling the base implementation as it must do:

    protected override void OnLoad(EventArgs e)
    {
       //... etc.
       base.OnLoad(e);
    }
    

    When overriding OnLoad(EventArgs) in a derived class, be sure to call the base class's OnLoad(EventArgs) method so that registered delegates receive the event.

提交回复
热议问题