如何调整C#WPF程序,以适应任何屏幕分辨率 [英] How to resize C# WPF Program to fit any screen resolution

查看:152
本文介绍了如何调整C#WPF程序,以适应任何屏幕分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何调整我的C#WPF程序基本上适应任何屏幕分辨率。我想适合我的节目到电脑的 1280×1024 的的屏幕分辨率。我无法找到如何做到这一点正是任何信息,当然我可以钻机方案的尺寸,以适应特定的屏幕,但每一个电脑的屏幕分辨率可能是潜在的不同吧?我试图用在这里提供的显而易见的解决方案:调整大小WPF窗口及内容depening屏幕分辨率,但它并没有帮助的。

I am trying to figure out how to resize my C# WPF Program to essentially fit any screen resolution. I am trying to fit my program to a computer with a screen resolution of 1280 x 1024. I can't find any information on how to do this exactly, of course I could rig the dimensions of the program to fit the specific screen but every computers screen resolution could be potentially different right? I tried using the obvious solution that was provided here: Resize WPF Window and contents depening on screen resolution but it did not help at all.

即。我用:(另外,我不知道如果我需要将的Horizo​​ntalAlignment &放大器; VerticalAlignment 来拉伸为好,但无论如何,我是。)

i.e. I used: (Also, I wasn't sure if I needed to set the HorizontalAlignment & VerticalAlignment to "stretch" as well, but I did anyway.)

Title="my screen" Height="{Binding SystemParameters.PrimaryScreenHeight}" Width="{Binding SystemParameters.PrimaryScreenWidth}" WindowStartupLocation="CenterScreen" WindowState="Maximized">
    <Grid Name="myGrid" Background="LightGray" Margin="0,0,2,-30" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <TextBox Name="stuffTB" HorizontalAlignment="Left" Height="28" Margin="751,252,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="186" />



...

...

每当我跑我的 exe文件计算机与尺寸上的 1280×1024 的它切断这是我网格内容。任何意见或帮助将是巨大的,甚至是链接的例子将是真棒。先谢谢了。

Whenever I run my exe on the computer with the dimensions of 1280 x 1024 it cuts off contents that are in my grid. Any advice or help would be great, even links to examples would be awesome. Thanks in advance.

推荐答案

如果你真的想强制调整所有的控件在Windows中可以使用视框的 https://msdn.microsoft.com /pl-pl/library/system.windows.controls.viewbox%28v=vs.110%29.aspx

If you really want to force resize all the controls in the windows you can use ViewBox https://msdn.microsoft.com/pl-pl/library/system.windows.controls.viewbox%28v=vs.110%29.aspx

但IMO你这样做错误。设计良好的WPF UI的基础是:

But IMO you're doing it wrong. The basics of designing good WPF UI would be:


  1. 使用网格列,如果你想要的东西来保存窗口的某些部分/个行尽管内容

  2. 使用DockPanels,StackPanels,WrapPanels等ETO安排UI

  3. 使用的ScrollViewer才能够看到控件,如果他们有一些最小尺寸设置和具体决议,他们将得到切断

看看这个示例中,我已经为你创建

Look at this sample I've created for you

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="2*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="100" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Grid.ColumnSpan="2" Background="Blue" Orientation="Horizontal">
            <Button>Button</Button>
            <Button>Button</Button>
            <Button>Button</Button>
        </StackPanel>
        <DockPanel Grid.Row="1" Grid.Column="1">
            <Rectangle DockPanel.Dock="Right" Width="100" Fill="Red"></Rectangle>
            <Ellipse DockPanel.Dock="Left" Fill="AliceBlue"></Ellipse>
        </DockPanel>
        <ScrollViewer Grid.Row="1">
            <StackPanel>
                <Button Height="200"></Button>
                <Button Height="200"></Button>
                <Button Height="200"></Button>
                <Button Height="200"></Button>
                <Button Height="200"></Button>
                <Button Height="200"></Button>

                <Button Height="200"></Button>
                <Button Height="200"></Button>
            </StackPanel>
        </ScrollViewer>
    </Grid>

这篇关于如何调整C#WPF程序,以适应任何屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆