如果用户有多个屏幕,
如何在启动时在主屏幕或选择的屏幕上启动应用程序
最佳答案
这是基本代码。它使用 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/