How do I center a window onscreen in C#?

后端 未结 12 2034
情书的邮戳
情书的邮戳 2020-12-02 09:05

I need a way to center the current window. So for example, if a user pushes a button, I want the window to center itself onscreen. I know you can use the startposition prope

12条回答
  •  無奈伤痛
    2020-12-02 09:44

    1. Using the Property window

      Select form → go to property window → select "start position" → select whatever the place you want.

    2. Programmatically

      Form form1 = new Form(); form1.StartPosition = FormStartPosition.CenterScreen; form1.ShowDialog();

      Note: Do not directly call Form.CenterToScreen() from your code. Read here.

提交回复
热议问题