Problem StartPosition in C #?

I want to show my WinApp in the center of the screen, so I set the StartPosition property to CenterScreen , but the window does not appear in the center of the screen.

What about him? Did I miss something?

PS:
I show the window from the main window and using the button.

Edit:
The code I use to show the window.

 Form_CO form_CO = new Form_CO(); void button_CO_Click(object sender, EventArgs e) { try { //StaticVariables.Form_CO_IsShown is to prevent opening the same multiple windows if (!StaticVariables.Form_CO_IsShown) { form_CO = new Form_CO(); form_CO.Show(); StaticVariables.Form_CO_IsShown = true; } else { form_CO.WindowState = FormWindowState.Normal; form_CO.Activate(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } } 
0
source share
1 answer

FormStartPosition.CenterScreen can be a problem if the form is repainted, adapting to the DPI setting of the video. Paste this code into your form to fix it:

  protected override void OnLoad(EventArgs e) { var scr = Screen.FromPoint(this.Location); this.Left = scr.WorkingArea.Left + (scr.WorkingArea.Width - this.Width) / 2; this.Top = scr.WorkingArea.Top + (scr.WorkingArea.Height - this.Height) / 2; base.OnLoad(e); } 
+3
source

Source: https://habr.com/ru/post/1342145/


All Articles