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

后端 未结 8 1561
夕颜
夕颜 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:14

    To center on parent for the .Show call, this is what I had to do:

    childForm.Location = new Point(
        (parentForm.Location.X + parentForm.Width / 2) - (childForm.Width / 2), 
        (parentForm.Location.Y + parentForm.Height / 2) - (childForm.Height / 2));
    childForm.StartPosition = FormStartPosition.Manual;
    

提交回复
热议问题