FormStartPosition.CenterParent does not work

前端 未结 13 1025
独厮守ぢ
独厮守ぢ 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条回答
  •  余生分开走
    2021-01-01 09:42

    Maybe this can help somebody.

    Form frmMessage = new Form();
    

    From experience, although they look similar, they behave different:

    This variant doesn't work:

    if (frmMessage.Parent != null)
        frmMessage.CenterToParent();
    else
        frmMessage.CenterToScreen();
    

    And this variant works

    if (frmMessage.Parent != null)
        frmMessage.StartPosition = FormStartPosition.CenterParent;
    else
        frmMessage.StartPosition = FormStartPosition.CenterScreen;
    

提交回复
热议问题