从辅助屏幕上的主屏幕更改后,我试图将表单位置更改为居中
private void Form2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
ff = !ff;
if(ff)
showOnScreen(1,this);
else
showOnScreen(0,this);
}
}
void showOnScreen(int screenNumber,Form frm)
{
Screen[] screens = Screen.AllScreens;
if (screenNumber >= 0 && screenNumber < screens.Length)
{
Location = screens[screenNumber].WorkingArea.Location;
this.Location = new Point((screens[screenNumber].Bounds.Size.Width / 2) - (this.Size.Width / 2), (screens[screenNumber].Bounds.Size.Height / 2) - (this.Size.Height / 2));
}
}
表格在屏幕中央移动,但仅在我的主屏幕上移动