我有一个包含多个 win 表单的应用程序。我注意到如果用户有多个屏幕显示并将应用程序更改为一个屏幕,则其他按钮调用的其他表单将在主显示中打开,而不是我的主应用程序或表单所在的位置。
我怎样才能改变这个?
最佳答案
您可以使用 Form.CenterToParent
表单上的方法,然后它们会以您创建的表单为中心打开,或者您可以使用 Screen 类获取运行主应用程序的显示器的边界,然后将其传递给您创建的表单。
编辑:
重新考虑分配 Owner
可能就足够了,但我此时没有启动双显示器计算机进行测试
Dim frm As Form1 = New Form1()
frm.Owner = Me
frm.CenterToParent()
frm.Show()
编辑
才有机会去看看。就像我想的那样分配
Owner
到新Form
或使用 Form.Show(IWin32Window)
将开新Form
在与原始 Form
相同的屏幕上.frm.Show(Me)
看起来像
CenterToParent
属性(property)现在受到保护。根据MSDN链接
Do not call the CenterToParent method directly from your code. Instead, set the StartPosition property to CenterParent. If the form or dialog is top-level, then CenterToParent centers the form with respect to the screen or desktop
关于vb.net - 在同一屏幕中打开 winforms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18050159/