zoukankan      html  css  js  c++  java
  • Winform如何保存自定义属性

    1.在设计界面中选择控件,然后在属性窗口选择数据->ApplicationSettings,然后选择font,新建一个fontsize

    2.添加控制类

        public class fontcontrol
        {
            //AppConfig ac = new AppConfig();
            public float Size
            {
                get
                {
                    return PE_TEST.Properties.Settings.Default.fontsize.Size;
                }
                set
                {
                    Font f = PE_TEST.Properties.Settings.Default.fontsize;
                    Font nf = new Font(f.FontFamily, value, f.Style, f.Unit);
                    PE_TEST.Properties.Settings.Default.fontsize = nf;
                    //Properties.Settings.Default.Save();
                }
            }
        }

    3.在窗口类的事件响应中调用

            private void Btnadd_Click(object sender, EventArgs e)
            {
                FontCtrl.Size++;
            }


    4.点击项目属性中的“设置”中的查看代码,vs自动生成Settings.cs文件。在Settings.cs中的初始化中绑定事件
            public Settings() {
                // // 若要为保存和更改设置添加事件处理程序,请取消注释下列行:
                //
                // this.SettingChanging += this.SettingChangingEventHandler;
                //
                // this.SettingsSaving += this.SettingsSavingEventHandler;
                //
                this.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Settings_PropertyChanged);
            }

    5.在Settings.cs中的PropertyChanged事件响应函数中

            void Settings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
                Settings s = sender as Settings;
                s.Save();
            }

  • 相关阅读:
    流畅的python——2 数据结构
    流畅的python——1 数据模型
    cpp3 std::bind
    cpp2 std::forward
    什么是 jQuery EasyUI?
    .Core中什么事依赖注入?
    .net 中datetime? 和 datetime 有什么区别?
    C#生成项目失败 错误列表 CS2001 未能找到源文件 “D:XXXXXX.cs”。
    Docker笔记
    ICollection与IEnumerable
  • 原文地址:https://www.cnblogs.com/qiu2013/p/qiu.html
Copyright © 2011-2022 走看看