/// 检验ucDropControlGroup中的Controller的拖拽 /// <summary> /// 检验ucDropControlGroup中的Controller的拖拽 /// </summary> /// <param name="sender">目标控件</param> /// <param name="e">源控件</param> /// <returns></returns> private bool CheckBeforeDropController(object sender, DragEventArgs e) { if (!UtilControl.CheckDragType_PictureBox(e)) { return(false); } PictureBox pbTarget = sender as PictureBox; // 目标控件 PictureBox pbSrc = (PictureBox)e.Data.GetData(type_PictureBox); // 源控件 //不能自己拖向自己 if (pbTarget == pbSrc) { return(false); } ucDropController ucDropControllerSource = pbSrc.Parent is ucDropController ? (ucDropController)pbSrc.Parent : null; ucDropController ucDropControllerTarget = pbTarget.Parent is ucDropController ? (ucDropController)pbTarget.Parent : null; //不能目标不在controller group区域 if (ucDropControllerTarget == null) { return(false); } CentralController controllerTypeSource; if (ucDropControllerSource == null) { controllerTypeSource = (pbSrc.Tag as CentralController); } else { controllerTypeSource = ucDropControllerSource.TypeInfo; } if (controllerTypeSource == null) { return(false); } //目标ucDropController控件已经含有controller if (ucDropControllerTarget.IsActive) { //如果不是同一种控制器,则不允许拖上去 if (controllerTypeSource.Model != ucDropControllerTarget.TypeInfo.Model) { return(false); } } //目标ucDropController控件是空白的 else { // 若属于同一个ucDropControlGroup,则不可以拖拽 if (pbSrc.Parent.Parent is ucDropControlGroup && pbSrc.Parent.Parent == this) { return(false); } //如果已经存在此型号的controller则不允许添加 if (this.HasControllerType(controllerTypeSource.Model)) { return(false); } } //拖动的controller的数量 int addNumber = 1; if (ucDropControllerSource != null && ucDropControllerSource.Controller != null) { addNumber = ucDropControllerSource.Controller.Quantity; } ListViewItem item = (ListViewItem)e.Data.GetData(type_ListViewItem, false); //继续检查 return(CheckBeforeAddController(controllerTypeSource, addNumber)); }