using DevExpress.XtraEditors; using Ips.Library.Basic; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Ips.Library.DxpLib { public class EditorHelper { public static void SaveEditorToAppConfig(Control container) { if (container == null) return; foreach (Control ctrl in container.Controls) { if (ctrl is BaseEdit) { var self = (BaseEdit)ctrl; var objVal = self.EditValue; ToolConfig.SetAppSetting(self.Name, objVal == null ? "" : objVal.ToString()); } else { SaveEditorToAppConfig(ctrl); } } } public static void LoadEditorFromAppConfig(Control container) { if (container == null) return; foreach (Control ctrl in container.Controls) { if (ctrl is BaseEdit) { var self = (BaseEdit)ctrl; string configVal = ToolConfig.GetAppSetting(self.Name); if (self is CheckEdit) { bool bVal; bool.TryParse(configVal, out bVal); self.EditValue = bVal; } else { if (self.EditValue != null && self.EditValue is Enum) { self.EditValue = configVal.To(self.EditValue); } else { self.EditValue = configVal; } } } else { LoadEditorFromAppConfig(ctrl); } } } } }