gpt4 book ai didi

c# - 在两个单独的屏幕上加载两个窗口

转载 作者:行者123 更新时间:2023-12-03 10:29:53 28 4
gpt4 key购买 nike

我正在尝试创建WPF演示应用程序,其中“主屏幕”上的“主窗口”将用于更新“演示窗口”上的内容,该内容需要在辅助屏幕上。我正在寻找可以帮助我做到这一点的示例或代码段。

另外,我尝试了以下操作,但不起作用:

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

var screens = System.Windows.Forms.Screen.AllScreens;
if (screens.Length > 1)
{
var window = new MainWindow
{
WindowStartupLocation = WindowStartupLocation.Manual,
WindowState = WindowState.Maximized,

Top = screens[0].WorkingArea.Top,
Left = screens[0].WorkingArea.Left,
Topmost = true
};
window.Show();

var pesentationWindow = new PresentationWindow
{
WindowStartupLocation = WindowStartupLocation.Manual,
ShowInTaskbar = false,
Top = screens[1].WorkingArea.Top,
Left = screens[1].WorkingArea.Left,
Topmost = true
};
pesentationWindow.Show();
}
}

最佳答案

您可以通过这种方式使用Screen对象

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

Window1 w1 = new Window1();
Window2 w2 = new Window2();


Screen s1 = Screen.AllScreens[0];
Screen s2 = Screen.AllScreens[1];

Rectangle r1 = s1.WorkingArea;
Rectangle r2 = s2.WorkingArea;

w1.Top = r1.Top;
w1.Left = r1.Left;

w2.Top = r2.Top;
w2.Left = r2.Left;

w1.Show();
w2.Show();

w2.Owner = w1;


}

请关注此 link以获取更多详细信息。

关于c# - 在两个单独的屏幕上加载两个窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10300496/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com