zoukankan      html  css  js  c++  java
  • ApplicationSettingsBase: 关掉WPF 窗口后,再次打开,显示在上次关闭的位置

    体验比较好的设计,用户再次打开程序的时候,还原到上次关闭前的位置。

    当然了,用户上次设置的颜色,字体等信息,都可以用同样的办法搞定。

     1   /// <summary>
     2     /// Interaction logic for MainWindow.xaml
     3     /// </summary>
     4     public partial class MainWindow : Window
     5     {
     6         WindowApplicationSettings settings = new WindowApplicationSettings();
     7 
     8         public MainWindow()
     9         {
    10             InitializeComponent();
    11             this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
    12             this.Closing += new CancelEventHandler(MainWindow_Closing);
    13         }
    14 
    15         void MainWindow_Closing(object sender, CancelEventArgs e)
    16         {
    17             settings.WinText = tb.Text;
    18             settings.WinLocation = new Point(this.Left, this.Top);
    19             settings.Save();
    20         }
    21 
    22         void MainWindow_Loaded(object sender, RoutedEventArgs e)
    23         {
    24             settings.Reload();
    25             tb.Text = settings.WinText;
    26             this.Left = settings.WinLocation.X;
    27             this.Top = settings.WinLocation.Y;
    28         }
    29     }
    30 
    31     /// <summary>
    32     /// Helper class used to save the settings in configuration file
    33     /// </summary>
    34     public class WindowApplicationSettings : ApplicationSettingsBase
    35     {
    36         [UserScopedSettingAttribute()]
    37         public String WinText
    38         {
    39             get { return (String)this["WinText"]; }
    40             set { this["WinText"] = value; }
    41         }
    42 
    43         [UserScopedSettingAttribute()]
    44         [DefaultSettingValueAttribute("0, 0")]
    45         public Point WinLocation
    46         {
    47             get { return (Point)(this["WinLocation"]); }
    48             set { this["WinLocation"] = value; }
    49         }
    50 
    51     }
  • 相关阅读:
    Firefox功能强大的浏览器 (转)
    常用的dnet开源项目
    15 个 JavaScript Web UI 库
    关于Web路径的备忘
    推荐几个.NET开源图表组件(转)
    C#开源资源大汇总 (转)
    jQuery对select操作小结 转载
    非对称加密RSA的应用及在C#中的实现(转)
    Web开发人员应当知道的15个开源项目
    css中float和列表图片liststyleimage不能正常解析的说明
  • 原文地址:https://www.cnblogs.com/xiaokang088/p/2567796.html
Copyright © 2011-2022 走看看