c# - Wpf 在主屏幕中启动

标签 c# .net wpf

如果用户有多个屏幕,

如何在启动时在主屏幕或选择的屏幕上启动应用程序

最佳答案

这是基本代码。它使用 WinForms,但我不知道有纯 WPF 解决方案。

using System;
using System.Windows;
using System.Windows.Forms;

namespace Foo
{
    public class WindowUtility
    {
        public static void MoveToMonitor(Window window, int monitorId, bool maximize)
        {
            Screen[] screens = Screen.AllScreens;

            int screenId = monitorId - 1;

            if (screens.Length > 1 && screenId < screens.Length)
            {
                var screen = screens[screenId];
                var area = screen.WorkingArea;

                if (maximize)
                {
                    window.Left = area.Left;
                    window.Top = area.Top;
                    window.Width = area.Width;
                    window.Height = area.Height;
                }
                else
                {
                    window.Left = area.Left;
                    window.Top = area.Top;
                }
            }
        }
    }
}

关于c# - Wpf 在主屏幕中启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6324276/

相关文章:

c# - MVVM SelectedItem.Property OnChanged MVVM SelectedItem.Property OnChanged

c# - 从代码隐藏更改 IFrames InnerHtml

c# - TextBox 中不显示换行符

.net - 我收到错误 "Application"在命名空间 'microsoft.office.interop.excel' 中不明确

c# - 用于文本算法的 .NET 库?

C#.NET : How to design a template and multiply it in a form

wpf - 在 WPF 上查询 MVVM 设计模式

c# - XAML 绑定(bind)到复杂值对象

c# - 如何在 MVC 中的另一个页面中显示 html 页面的一部分

c# - 如何使任务失败然后断言异常