示例#1
0
        public void Save(string path)
        {
            var settings = new IniSettings();

            foreach (var prop in properties.Values)
            {
                if (prop.PropertyType == typeof(Color))
                {
                    settings.Set(prop.Name, "#" + (((Color)prop.GetValue(this, null)).ToArgb() & 0xFFFFFF).ToString("X"));
                }
                else if (prop.PropertyType == typeof(Brush))
                {
                    var value      = prop.GetValue(this, null);
                    var solidBrush = value as SolidBrush;
                    if (solidBrush != null)
                    {
                        settings.Set(prop.Name, "#" + ((solidBrush.Color).ToArgb() & 0xFFFFFF).ToString("X"));
                    }
                }
                else if (prop.PropertyType == typeof(Pen))
                {
                    var value      = prop.GetValue(this, null);
                    var solidBrush = (value as Pen)?.Brush as SolidBrush;
                    if (solidBrush != null)
                    {
                        settings.Set(prop.Name, "#" + ((solidBrush.Color).ToArgb() & 0xFFFFFF).ToString("X"));
                    }
                }
            }

            settings.Save(path);
        }