/// <summary> /// 调整出口插槽链表 /// </summary> /// <param name="n">插槽数量</param> protected override void AdjustOutSlotList(int n) { int newX; int newY; Point newPoint = Point.Empty; if (n == outSlotList.Count) // 不需要调整插槽 { newX = location.X; newY = (int)(location.Y + elementSize.Height / 2); newPoint.X = newX; newPoint.Y = newY; outSlotList[0].Location = newPoint; outSlotList[0].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[0].Binded) // 调整绑定的连接线控制点 { outSlotList[0].BindingConnector.Location = newPoint; } newX = location.X + elementSize.Width; newY = (int)(location.Y + elementSize.Height / 2); newPoint.X = newX; newPoint.Y = newY; outSlotList[1].Location = newPoint; outSlotList[1].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[1].Binded) // 调整绑定的连接线控制点 { outSlotList[1].BindingConnector.Location = newPoint; } // 调整插糟的坐标 for (int i = 2; i < outSlotList.Count; i++) { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; outSlotList[i].Location = newPoint; outSlotList[i].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[i].Binded) // 调整绑定的连接线控制点 { outSlotList[i].BindingConnector.Location = newPoint; } } } else if (n < outSlotList.Count) // 需要减少插槽数量 { int deleteCount = outSlotList.Count - n; List <SlotGraphElement> deleteSlotList = new List <SlotGraphElement>(); for (int i = 0; i < deleteCount; i++) { deleteSlotList.Add(outSlotList[outSlotList.Count - 1 - i]); } foreach (SlotGraphElement slot in deleteSlotList) { if (slot.Binded) { slot.UnBind(); } buttonList.Remove(slot.BindingConnectButton); slot.BindingConnectButton = null; outSlotList.Remove(slot); slotList.Remove(slot); } // 调整插糟的坐标 for (int i = 2; i < outSlotList.Count; i++) { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; outSlotList[i].Location = newPoint; outSlotList[i].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[i].Binded) // 调整绑定的连接线控制点 { outSlotList[i].BindingConnector.Location = newPoint; } } } else // 需要增加插槽数量 { Helper helper = Helper.GetHelper(); int oldCount = outSlotList.Count; SlotGraphElement newSlot; // 添加插槽并调整插槽的坐标 for (int i = 2; i < n; i++) { if (i < oldCount) { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; outSlotList[i].Location = newPoint; outSlotList[i].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[i].Binded) // 调整绑定的连接线控制点 { outSlotList[i].BindingConnector.Location = newPoint; } } else { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; newSlot = new SlotGraphElement(this, newPoint, new Size(6, 6)); newSlot.Name = "连接插槽"; newSlot.IsOutSlot = true; newSlot.CanDelete = true; newSlot.Refresh(); ConnectButton button = new ConnectButton(newSlot, new Point(newX - 6, location.Y + elementSize.Height + 25), new Size(12, 8)); button.Name = "连接按钮"; button.Refresh(); newSlot.BindingConnectButton = button; outSlotList.Add(newSlot); buttonList.Add(button); slotList.Add(newSlot); } } } ResetSlotProperty(outSlotList); }