小编The*_*mer的帖子

C# WPF 窗口:错误的宽度和实际宽度值

我刚刚用 C# 编写了一个小程序,可以在我的桌面上显示引号。我的问题是将应用程序的窗口居中。要计算所需的窗口位置,我使用以下公式:

        Left = (Screen.PrimaryScreen.Bounds.Width - this.ActualWidth) / 2;
        Top = (Screen.PrimaryScreen.Bounds.Height - this.ActualHeight) / 2;
Run Code Online (Sandbox Code Playgroud)

不幸的是 this.ActualWidth 和 this.ActualHeight 给出了错误的值,如您在屏幕截图中所见。188,4 和 189 而不是 1000(+)。

http://www.directupload.net/file/d/4044/4x2tgadg_png.htm

这是图形用户界面:

http://www.directupload.net/file/d/4044/63rx2sul_png.htm

文本形式的代码:

public partial class QuotePresenter : Window
{
    public QuotePresenter()
    {
        InitializeComponent();
        setSize();
    }

    private void setSize()
    {
        MaxWidth = Screen.PrimaryScreen.Bounds.Width * 0.8;
        MaxHeight = Screen.PrimaryScreen.Bounds.Height * 0.8;
    }

    private void setLocation()
    {
        Left = (Screen.PrimaryScreen.Bounds.Width - this.ActualWidth) / 2;
        Top = (Screen.PrimaryScreen.Bounds.Height - this.ActualHeight) / 2;

        System.Windows.MessageBox.Show("Actual Width: " + …
Run Code Online (Sandbox Code Playgroud)

c# size wpf window

4
推荐指数
1
解决办法
2630
查看次数

标签 统计

c# ×1

size ×1

window ×1

wpf ×1