【发布时间】:2010-12-24 21:23:06
【问题描述】:
我有一个双显示器设置,我希望我的 c# 应用程序在特定屏幕上最大化其窗口。
我该怎么做?
谢谢!
【问题讨论】:
-
这个解决方案唤醒了我:stackoverflow.com/questions/17103989
标签: .net windows winforms maximize
我有一个双显示器设置,我希望我的 c# 应用程序在特定屏幕上最大化其窗口。
我该怎么做?
谢谢!
【问题讨论】:
标签: .net windows winforms maximize
Public Shared Sub MoveForm(Item As Form, ScreenNumber As Integer, Optional X As Integer = 0, Optional Y As Integer = 0)
With Screen.AllScreens(ScreenNumber).Bounds
X -= .Left 'translate overall coordinates to screen coordinates
Y -= .Top
End With
Item.Location = New System.Drawing.Point(X, Y)
End Sub
【讨论】:
这是我的一个项目中类似范围的屏幕管理代码:
// screenId in my case is 1(first) or 2(second)
int screenId = RegistryManager.ScreenId;
// DualScreen management
if (screenId > 0)
{
// Have 2 screens
if (System.Windows.Forms.Screen.AllScreens.Length == 2)
{
if (screenId == 1) // first
this.Location = new System.Drawing.Point(System.Windows.Forms.Screen.AllScreens[0].Bounds.Left, 0);
else // second
this.Location = new System.Drawing.Point(System.Windows.Forms.Screen.AllScreens[1].Bounds.Left, 0);
}
}
【讨论】:
您使用 Screen 类来查找第二个监视器 link
找到代码here
function void showOnMonitor2()
{
Screen[] sc;
sc = Screen.AllScreens;
//get all the screen width and heights
Form2 f = new Form2();
f.FormBorderStyle = FormBorderStyle.None;
f.Left = sc[1].Bounds.Width;
f.Top = sc[1].Bounds.Height;
f.StartPosition = FormStartPosition.Manual;
f.Location = sc[1].Bounds.Location;
Point p = new Point(sc[1].Bounds.Location.X, sc[1].Bounds.Location.Y);
f.Location = p;
f.WindowState = FormWindowState.Maximized;
f.Show();
}
【讨论】:
您可以通过在最大化之前将窗口一直向右或向左移动来实现此功能。这应该会导致窗口在最大化时最大化到该屏幕。
【讨论】: