问题描述
我已经编辑了一个程序(c#),它在主屏幕上加载一个表单,当我点击确定时它会在窗体上显示不同的文本,但问题是我正在使用双显示器,所以当我在主屏幕中加载表单并拖动它时到辅助屏幕并点击确定它会自动移回主屏幕,我不想要,我希望它留在我移动的地方,
i写了一个确定的方法在哪个屏幕表格当前加载哪个是好的然后当我试图重新定位它意味着二级屏幕它不再工作它移回主屏幕我不知道这里出错是我的代码
I have wriiten a Programme(c#) which loads a form in Primary screen it displays different Texts on form when i click ok but the problem is i am working with dual monitor so when i load a form in Primary screen and drag it to Secondary screen and click ok it automatically moved back to primary screen which i dont want, i want it to stay where i moved to,
i have written a methode which determines on which screen Form is currently loaded which is ok and then when i tries to relocate it means to secondary screen its not working again its moving back to primary screen i dont know whats goes wrong here is my code
if(Currentscreen == "primary")
{
forma.showDialog(this);//this is ok showing form on main screen
}
else
{
int showOnMonitor = 1;
Screen[] scr;
scr = Screen.AllScreens;
forma.StartPosition = FormStartPosition.CenterParent;
forma.Location = new Point(sc[showOnMonitor].Bounds.Left, sc[showOnMonitor].Bounds.Top);//this line should relocate it on secondary screen
forma.showDialog(this);//but its again loading on Primary monitor
}
不知道哪里出错
dont know where it goes wrong
推荐答案
if (Screen.AllScreens.Length > 1)
myForm.Location = Screen.AllScreens[1].WorkingArea.Location;
想要改进一下,把它放在那个屏幕的中心?取屏幕大小,表格大小,计算班次并将其添加到上面显示的位置。
这篇关于如何在辅助屏幕中设置表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!