using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.XtraEditors; using DevExpress.XtraTreeList.Nodes; using GeoSigma.SigmaDrawerUtil; using UCDraw; namespace PcgDrawR { public partial class FrmOptions : DevExpress.XtraEditors.XtraForm { private DrawerConfig sysConfig; public FrmOptions() { InitializeComponent(); this.LoadData(); } /// /// 加载配置数据. /// private void LoadData() { this.sysConfig = DrawerConfig.Instance.Clone(); this.trlDataItem.Nodes.Clear(); // 系统设置节点 foreach (var node in this.sysConfig.ConfigNodes) { if (node.Display == true) { TreeListNode tln = this.trlDataItem.Nodes.Add(new object[] { node.Caption, node.Name }); tln.ImageIndex = 1; tln.Tag = node.ConfigItems; } } trlDataItem.ExpandAll(); } /// /// trls the data item_ focused node changed. /// /// The sender. /// The e. private void trlDataItem_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { if (e.Node == null) { return; } object obj = e.Node.Tag; if (obj != null) { this.propertyGridControl1.SelectedObject = (CustomProperties)obj; } else { this.propertyGridControl1.SelectedObject = null; } } /// /// btns the o k_ click. /// /// The sender. /// The e. private void btnOK_Click(object sender, EventArgs e) { this.sysConfig.Save(); DrawerConfig.Instance = this.sysConfig; this.DialogResult = DialogResult.OK; } /// /// Frms the options_ load. /// /// The sender. /// The e. private void FrmOptions_Load(object sender, EventArgs e) { if (this.trlDataItem.Nodes.Count > 0) { trlDataItem_FocusedNodeChanged( this.trlDataItem , new DevExpress.XtraTreeList.FocusedNodeChangedEventArgs(null, this.trlDataItem.Nodes[0])); } } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } private void propertyGridControl1_CustomPropertyDescriptors(object sender, DevExpress.XtraVerticalGrid.Events.CustomPropertyDescriptorsEventArgs e) { if (e.Context.PropertyDescriptor == null) { e.Properties = e.Properties.Sort(new PropertyOrderComparer()); } } public class PropertyOrderComparer : IComparer { /// int IComparer.Compare(object a, object b) { if ((a is CustomPropDescriptor) && (b is CustomPropDescriptor)) { return ((CustomPropDescriptor)a).PropertyOrder.CompareTo(((CustomPropDescriptor)b).PropertyOrder); } return new CaseInsensitiveComparer().Compare(a, b); } } } }