How do you set the StartPosition of a Windows Forms form using code?

后端 未结 8 1562
夕颜
夕颜 2020-12-18 20:55

Is there a way to set the StartPosition of a Windows Forms form using code? It seems whatever I try results in the StartPostion being the default.

Here is what I am

8条回答
  •  爱一瞬间的悲伤
    2020-12-18 21:15

    You can do this by calling this.CenterToParent() in the Form_Load event (when the parent is actually known). Don't call this in the Constructor because the parent it set when Show(form) is called.

    private void myForm_Load(object sender, EventArgs e)
    {
        CenterToParent();
    }
    

    I know this thread is old but it can be answered pretty easily so hopefully help others who come across it find the easy solution.

提交回复
热议问题