WebEnh

.net7 mvc jquery bootstrap json 学习中 第一次学PHP,正在研究中。自学进行时... ... 我的博客 https://enhweb.github.io/ 不错的皮肤:darkgreentrip,iMetro_HD
随笔 - 1079, 文章 - 1, 评论 - 75, 阅读 - 174万
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

C#WPF的多屏显示问题

Posted on   WebEnh  阅读(300)  评论(1编辑  收藏  举报

如果想让窗口在第二个屏幕中显示

public MainWindow()
{
InitializeComponent();
Screen[] _screens = Screen.AllScreens;
Screen s = Screen.AllScreens[1];
System.Drawing.Rectangle rect = s.WorkingArea;
this.Left = rect.Left;
this.Top = rect.Top;
}
如果想在拓展桌面中2个显示器同时显示一个窗口内容

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

foreach (var screen in System.Windows.Forms.Screen.AllScreens)
{
var window = new Window1
{
WindowStartupLocation = WindowStartupLocation.Manual,
WindowState = WindowState.Maximized,
WindowStyle = WindowStyle.None,
Title = screen.DeviceName,
Width = screen.Bounds.Width,
Height = screen.Bounds.Height,
Left = screen.Bounds.Left,
Top = screen.Bounds.Top,
};
window.Show();
}
}
不要忘记从 App.xaml 中删除 StartupUri="Window1.xaml"。

如果要在多个显示器中显示多个窗口,则

List<Screen> screens = Screen.AllScreens.ToList();
获取所有显示器的数量,把窗口显示到对应的屏幕上

ChildLPeriod childLPeriod = new ChildLPeriod(mainViewmodel);
childLPeriod.DataContext = mainViewmodel;

Display(childLPeriod, screens[1]);
Display函数

public void Display(Window _window, System.Windows.Forms.Screen screen)

{
Window window = _window as Window;
if (window != null)
{
window.Top = 0;
window.Left = screen.WorkingArea.Left;
window.Width = screen.WorkingArea.Width;
window.Height = screen.WorkingArea.Height;
window.Loaded += Window_loaded;
window.Show();
}
}

————————————————

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原文链接:https://blog.csdn.net/xuehuavickie/article/details/130425684

相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示

喜欢请打赏

扫描二维码打赏

了解更多