using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing.Design; using System.ComponentModel; using System.Windows.Forms.Design; using System.Windows.Forms; using System.Collections; using System.ComponentModel.Design.Serialization; using System.Reflection; namespace Mesnac.Controls.Intake.Base { public class LinkControlEditor : UITypeEditor { public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { if (context != null && context.Instance != null) { return UITypeEditorEditStyle.Modal; } return base.GetEditStyle(context); } public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { IWindowsFormsEditorService editorService = null; if (context != null && context.Instance != null && provider != null) { System.ComponentModel.Design.IDesignerHost host = context.GetService(typeof(System.ComponentModel.Design.IDesignerHost)) as System.ComponentModel.Design.IDesignerHost; editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (editorService != null) { System.ComponentModel.Design.ISelectionService ss = context.GetService(typeof(System.ComponentModel.Design.ISelectionService)) as System.ComponentModel.Design.ISelectionService; if (ss != null) { System.Collections.ICollection ic = ss.GetSelectedComponents(); object[] selectedcomp = new object[ic.Count]; ic.CopyTo(selectedcomp, 0); if (selectedcomp.Length == 1) { IntakeControl intakeControl = selectedcomp[0] as IntakeControl; if (intakeControl.LinkControl == null) { intakeControl.LinkControl = ""; } string currentPropertyName = context.PropertyDescriptor.Name; string currentPropertyValue=""; if (currentPropertyName == "LinkControl") { currentPropertyValue=intakeControl.LinkControl; } else if (currentPropertyName == "LinkControlB") { currentPropertyValue = intakeControl.LinkControlB; } LinkControlForm dlg = new LinkControlForm(currentPropertyValue); dlg.lblName.Text ="当前所选控件:"+ intakeControl.Name+"请选择该控件的流动输出"; List nodeList = new List(); dlg.InitContorl = new List(); foreach (Component cmp in host.Container.Components) { if (cmp is IntakeControl) { nodeList.Add(cmp.GetType().Name); if (intakeControl.Name != cmp.Site.Name) { if (cmp.Site.Name.IndexOf("ForkValveInTwo") >= 0) { dlg.InitContorl.Add(cmp.Site.Name + "平"); dlg.InitContorl.Add(cmp.Site.Name + "侧"); dlg.lsInit.Items.Add(cmp.Site.Name + "平"); dlg.lsInit.Items.Add(cmp.Site.Name + "侧"); } else { dlg.lsInit.Items.Add(cmp.Site.Name); dlg.InitContorl.Add(cmp.Site.Name); } } } } #region 绑定组件类型 IList Update_list= new List(); var ulist = (from li in nodeList select li).Distinct(); foreach (var d in ulist) { Update_list.Add(d); } TreeNode rootNode = new TreeNode(); rootNode.Text = "全部"; dlg.tvType.Nodes.Add(rootNode); foreach (string node in Update_list) { TreeNode Node = new TreeNode(); switch (node) { case "AirStraightTube": Node.Text = "横管"; Node.Tag = "AirStraightTube"; Node.ImageIndex =1; Node.SelectedImageIndex = 1; break; case "ForkValveInTwo": Node.Text = "岔道阀(进2)"; Node.Tag = "ForkValveInTwo"; Node.ImageIndex = 2; Node.SelectedImageIndex = 2; break; case "ForkValveOutTwo": Node.Text = "岔道阀(出2)"; Node.Tag = "ForkValveOutTwo"; Node.ImageIndex = 0; Node.SelectedImageIndex = 0; break; case "AirOnoffValve": Node.Text = "通断阀"; Node.Tag = "AirOnoffValve"; Node.ImageIndex = 3; Node.SelectedImageIndex = 3; break; default: break; } rootNode.Nodes.Add(Node); rootNode.Expand(); } #endregion #region 点击确定按钮 if (dlg.ShowDialog() == DialogResult.OK) { if (dlg.lsSelect.Items.Count > 0) { value = dlg.lsSelect.Items[0].ToString(); } else value = ""; return value; } #endregion } } } } return value; } } }