在WPF最小化窗口的位置 [英] Minimized window position in WPF

查看:182
本文介绍了在WPF最小化窗口的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存自定义对话框,用户注册表的位置,这样,当他们重新加载相同的对话框,它会出现在他们移动或调整到以前一样的地方。
我节省了窗户X位置Y位置宽度和高度。这一切都工作正常,除非被最小化的对话框。如果对话框最小化,用鼠标右击任务栏上的对话表示(Windows 7)中,他们可以点击关闭此窗口。奇怪的是,数-32030被保存在注册表中的X和Y位置,但宽度和高度得到正确保存。其中,这个数字来源于什么任何想法,在这种情况下THX做

I am trying to save the position of a custom dialog to the users registry, so that when they reload the same dialog, it appears in the same place they moved or resized it to previously. I am saving the windows X position Y position Width and Height. It all works fine except for when the dialog is minimized. If the dialog is minimized and the user right clicks the dialogs representation on the taskbar (windows 7) they can click "close this window". Strangely, the number -32030 gets saved in the registry as the X and Y positions but the width and height get saved correctly. Any idea where this number comes from and what to do in this situation thx

推荐答案

您想是这样的,当你保存窗口位置:

You want something like this when you save the window position:

if (this.WindowState == WindowState.Normal)
{
    Properties.Settings.Default.Top = Top;
    Properties.Settings.Default.Left = Left;
    Properties.Settings.Default.Height = Height;
    Properties.Settings.Default.Width = Width;
}
else
{
    Properties.Settings.Default.Top = RestoreBounds.Top;
    Properties.Settings.Default.Left = RestoreBounds.Left;
    Properties.Settings.Default.Height = RestoreBounds.Height;
    Properties.Settings.Default.Width = RestoreBounds.Width;
    // Check for WindowState.Maximized or WindowState.Minimized if you
    // need to do something different for each case (e.g. store if application
    // was Maximized
}

最重要的一点是 RestoreBounds 您需要当最大化或最小化窗口,代码大概可以重构,以使其更有效率,但你的想法。

The important bit is the RestoreBounds which you need when the window is maximised or minimised. The code can probably be refactored to make it more efficient, but you get the idea.

这篇关于在WPF最小化窗口的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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