zoukankan      html  css  js  c++  java
  • Wpf配置文件属性

      public MainWindow()
            {
                InitializeComponent();
                this.WindowState = Properties.Settings.Default.WindowState;//初始化窗体状态  Properties:配置文件的命名空间
    
                Rect rect = Properties.Settings.Default.WindowRect; //初始化窗体位置
                this.Top = rect.Top;
                this.Left = rect.Left;
                this.Width = rect.Width;
                this.Height = rect.Height;
            }
    
            private void Button_Click_1(object sender, RoutedEventArgs e)//显示坐标及大小
            {
                MessageBox.Show(this.RestoreBounds.ToString()); //RestoreBounds窗体坐标及大小
            }
    
            private void Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)//窗体关闭前触发
            {
                Properties.Settings.Default.WindowState = this.WindowState;//初始化窗体状态
    
                Properties.Settings.Default.WindowRect = this.RestoreBounds;
                Properties.Settings.Default.Save();
                //e.Cancel = true;//不能点击关闭按钮
                //隐藏之后f便不为空了,所以点击主窗体的时候小窗体已经弹出来了,但是只是隐藏了还没有关闭,所有要关闭它
                if (f != null)
                {
                    f.Close();
                }
            }
            Window1 f;
            private void Button_Click_2(object sender, RoutedEventArgs e)
            {   
                //加if条件是为了保证唯一实例化
                if (f == null)
                {
                    f = new Window1();
                    f.Show();
                }
                else
                {
                    f.Show();
                }
    
            }
    
            private void Button_Click_3(object sender, RoutedEventArgs e)
            {
                //加if条件是为了保证唯一实例化,杜绝资源的浪费
                if (f != null)
                {
                    f.Hide();
                }
                else
                {
                    MessageBox.Show("请先打开窗口再执行隐藏"); 
                }
            }
  • 相关阅读:
    写在寒假
    Docker安装Redis(两种方式)
    JVM类加载机制
    RabbitMQ学习
    MySQL索引详解
    Java内存区域
    Window10下的Docker Desktop安装(保姆级教程)
    JVM垃圾回收
    力扣Hot100(目前进度89/100)
    C# 发送邮件实例
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4604797.html
Copyright © 2011-2022 走看看