主屏幕在虚拟屏幕中的位置

发布于 2024-11-03 00:52:38 字数 995 浏览 4 评论 0原文

我可以将 wpf 窗口置于主屏幕或虚拟屏幕中的某个位置。但是,我想将窗口拉伸到整个虚拟屏幕上,并在窗口中放置一个网格,使其填充主屏幕。下面的截图显示了如何拉伸窗口、添加网格并拉伸网格以适合主屏幕尺寸,但如何确定网格的位置(即边距)?

<Window x:Class="BC.Citrium.Screensaver.Saver.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" 
        Height="{x:Static SystemParameters.VirtualScreenHeight}" 
        Width="{x:Static SystemParameters.VirtualScreenWidth}"
        Top="{x:Static SystemParameters.VirtualScreenTop}"
        Left="{x:Static SystemParameters.VirtualScreenLeft}"
        ResizeMode="NoResize" WindowStyle="None">
    <Grid Name="mainGrid"
          Height="{x:Static SystemParameters.MaximizedPrimaryScreenHeight}" 
          Width="{x:Static SystemParameters.MaximizedPrimaryScreenWidth}"
          Margin="???"
          Background="Bisque">
    </Grid>
</Window>

我可以绘制两个窗口,一个适合虚拟屏幕,一个在上面适合主屏幕,但这不是好方法。

I can center a wpf window in somewhere in the primary screen or in the virtual screen. However, I want to stretch the window over the whole virtual screen and place e.g. a grid in the window in a way that it fills the primary screen. The following snipped shows how I stretch the window, add a grid and stretch the grid to fit the primary screen size, but how do I determine the position (i.e. margin) for the grid?

<Window x:Class="BC.Citrium.Screensaver.Saver.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" 
        Height="{x:Static SystemParameters.VirtualScreenHeight}" 
        Width="{x:Static SystemParameters.VirtualScreenWidth}"
        Top="{x:Static SystemParameters.VirtualScreenTop}"
        Left="{x:Static SystemParameters.VirtualScreenLeft}"
        ResizeMode="NoResize" WindowStyle="None">
    <Grid Name="mainGrid"
          Height="{x:Static SystemParameters.MaximizedPrimaryScreenHeight}" 
          Width="{x:Static SystemParameters.MaximizedPrimaryScreenWidth}"
          Margin="???"
          Background="Bisque">
    </Grid>
</Window>

I could draw two windows, one to fit the virtual screen and one above that to fit the primary screen, but that's not the nice way.

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

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

发布评论

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

评论(1

请止步禁区 2024-11-10 00:52:38

主屏幕的左上角始终位于屏幕位置 (0, 0)。这使得您想要使用的边距(-VirtualScreenLeft、-VirtualScreenTop)。调整窗口边框宽度和窗口标题高度。

The upper left corner of the primary screen is always at screen position (0, 0). Which makes the margin you want to use (-VirtualScreenLeft, -VirtualScreenTop). With adjustment for the window border width and the window caption height.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文