.NET/WinForms:在特定屏幕上最大化窗口

发布于 2024-08-13 14:34:11 字数 76 浏览 11 评论 0原文

我有一个双显示器设置,我希望我的 C# 应用程序在特定屏幕上最大化其窗口。

我怎样才能做到这一点?

谢谢!

i have a dual monitor setup and i want my c# application to maximize its window on a specific Screen.

how can i do that?

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南烟 2024-08-20 14:34:11

这是我的一个项目中类似范围的屏幕管理代码:

        // 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);
            }
        }

This is a screen management code for a similar scope in one of my projects:

        // 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);
            }
        }
落墨 2024-08-20 14:34:11

您使用 Screen 类查找第二个显示器链接< /a>

代码在此处找到

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();
}

You use the Screen class to find the 2nd monitor link

Code found 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();
}
独孤求败 2024-08-20 14:34:11

您可以通过在最大化之前将窗口一直向右或向左移动来实现此目的。这应该会导致窗口在最大化时最大化到该屏幕。

You might get this to work by moving the window all the way right or left before maximizing. This should cause the window to maximize to that screen when it does maximize.

滿滿的愛 2024-08-20 14:34:11
  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
  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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文