Пример #1
0
        public void ChangeBus(string Name)
        {
            if (BusModule != null)
            {
                if (BusModule.Name != Name && MessageBox.Show("Do you want to change bus type?", "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    this.Controls.Remove(BusModule);
                }
                else
                {
                    return;
                }
            }

            Enum.TryParse(Name, out EnumBusType BusType);
            BusModule = new BusModel(BusType, new Point(100, this.Height / 2 + 100));

            this.Controls.Add(BusModule);
            BusModule.BringToFront();
            BusModule.OnModleDelete    += UserControl1_OnModleDelete;
            BusModule.ControlMoveEvent += BusModule_ControlMoveEvent;
            BusModule_ControlMoveEvent(new object(), new ControlMoveEventArgs(""));
            OnProductChangedEvent?.Invoke(this, new ModuleAddedArgs()
            {
                IsAdd = true, Module = BusModule
            });
        }
Пример #2
0
        /// <summary>
        /// Middle——》Left
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void panel_Product_DragDrop(object sender, DragEventArgs e)
        {
            Point  point = this.PointToClient(new Point(e.X, e.Y));
            object info  = e.Data.GetData(typeof(string));

            List <string> ControlNameList = new List <string>();

            foreach (Control it in this.Controls)
            {
                if ((it as SubBusModel) != null)
                {
                    ControlNameList.Add((it as SubBusModel).Name);
                }
            }

            if (info.ToString().Contains("HL")) //子模块
            {
                if (BusModule == null)
                {
                    MessageBox.Show("Please add a bus first!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                var            ExistCount      = ControlNameList.Where(c => c.Contains(info.ToString())).Count();
                EnumDeviceName subBusModelType = (EnumDeviceName)Enum.Parse(typeof(EnumDeviceName), info.ToString().Substring(0, 6));
                SubBusModel    SubBusModule    = new SubBusModel(point, subBusModelType, ExistCount + 1, ControlNameList.Count + 1);

                SubBusModule.OnModleDelete += UserControl1_OnModleDelete;
                this.Controls.Add(SubBusModule);
                SubBusModule.BringToFront();
                SubBusModule.ControlMoveEvent += BusModule_ControlMoveEvent;
                BusModule_ControlMoveEvent(new object(), new ControlMoveEventArgs(""));

                OnProductChangedEvent?.Invoke(this, new ModuleAddedArgs()
                {
                    Module = SubBusModule, IsAdd = true
                });
            }
            else  //总线
            {
                ChangeBus(info.ToString());
            }
        }
Пример #3
0
 /// <summary>
 /// Middle->Left
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void UserControl1_OnModleDelete(object sender, EventArgs e)
 {
     if (sender is BusModel)
     {
         if (MessageBox.Show("You will delete all the submodules, do you want to delelte all submodules?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
         {
             List <ControlBase> ModuleList = new List <ControlBase>();
             BusModule = null;
             foreach (var it in this.Controls)
             {
                 if (it is ControlBase)
                 {
                     ModuleList.Add(it as ControlBase);
                 }
             }
             foreach (var it in ModuleList)
             {
                 it.Dispose();
             }
             BusModule_ControlMoveEvent(new object(), new ControlMoveEventArgs(""));
             OnProductChangedEvent?.Invoke(this, new ModuleAddedArgs()
             {
                 IsAdd = false, Module = sender as ControlBase
             });
         }
     }
     else
     {
         OnProductChangedEvent?.Invoke(this, new ModuleAddedArgs()
         {
             IsAdd = false, Module = sender as ControlBase
         });
         (sender as ControlBase).Dispose();
         BusModule_ControlMoveEvent(new object(), new ControlMoveEventArgs(""));
     }
 }