vb.net - 在同一屏幕中打开 winforms

标签 vb.net

我有一个包含多个 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/

相关文章:

vb.net - 如何使用 vb.net 将消息从一台计算机发送到另一台计算机?

asp.net - 缩小缓存数据范围的 Datatable.Select() 最快替代方案?

.net - 如何在 vb.net 中进行动态向下转型?

vb.net - 如何更新数据表

html - iTextSharp HTML 到 PDF 保留空间

c# - 如何使用 C# 或 VB 读取 SSL 证书的序列号?

.net - 从 RichTextBox 复制文本及其格式

wpf - 使用函数开始调用?

.net - 如何处理 System.Data.DataTableExtensions.CopyToDataTable() 中的缺陷

vb.net - 使文本适合 VB.net Windows 窗体中的文本框