/// <summary> /// 双击检查 /// </summary> /// <param name="item">The item.</param> /// <param name="mouseLocation">The mouse location.</param> /// <param name="blnDoExpansion">if set to <c>true</c> [BLN do expansion].</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> private bool CheckDrawRectClick(MindMappingItemEntity item, Point mouseLocation, bool blnDoExpansion = true) { if (item == null) { return(false); } else { if (item.DrawRectangle.Contains(mouseLocation)) { if (blnDoExpansion) { item.IsExpansion = !item.IsExpansion; } return(true); } if (item.Childrens != null && item.Childrens.Length > 0) { foreach (var child in item.Childrens) { var bln = CheckDrawRectClick(child, mouseLocation, blnDoExpansion); if (bln) { return(bln); } } } } return(false); }
/// <summary> /// 单击检查 /// </summary> /// <param name="item">The item.</param> /// <param name="mouseLocation">The mouse location.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> private bool CheckExpansionClick(MindMappingItemEntity item, Point mouseLocation) { if (item == null) { return(false); } else { if (item.DrawRectangle.Contains(mouseLocation)) { selectEntity = item; if (ItemClicked != null) { ItemClicked(item, null); } } if (item.ExpansionRectangle.Contains(mouseLocation)) { item.IsExpansion = !item.IsExpansion; return(true); } if (item.Childrens != null && item.Childrens.Length > 0) { foreach (var child in item.Childrens) { var bln = CheckExpansionClick(child, mouseLocation); if (bln) { return(bln); } } } } return(false); }
/// <summary> /// 画节点 /// </summary> /// <param name="item">The item.</param> /// <param name="g">The g.</param> private void DrawItem(MindMappingItemEntity item, Graphics g) { //节点 var size = g.MeasureString(item.Text, item.Font); item.DrawRectangle = new RectangleF(item.WorkingRectangle.Left + 2, item.WorkingRectangle.Top + (item.WorkingRectangle.Height - size.Height) / 2 + 2, size.Width + 4, size.Height + 4); GraphicsPath drawPath = item.DrawRectangle.CreateRoundedRectanglePath(5); if (item.BackColor.HasValue) { g.FillPath(new SolidBrush(item.BackColor.Value), drawPath); } else { g.FillPath(new SolidBrush(itemBackcolor), drawPath); } g.DrawString(item.Text, item.Font, new SolidBrush(item.ForeColor), item.DrawRectangle.Location.X + 2, item.DrawRectangle.Location.Y + 2); //子节点 if (item.Childrens != null && item.IsExpansion) { for (int i = 0; i < item.Childrens.Length; i++) { var child = item.Childrens[i]; if (i == 0) { child.WorkingRectangle = new RectangleF(item.DrawRectangle.Right + splitWidth, item.WorkingRectangle.Top, item.WorkingRectangle.Width - (item.DrawRectangle.Width + splitWidth), child.AllChildrensMaxShowHeight); } else { child.WorkingRectangle = new RectangleF(item.DrawRectangle.Right + splitWidth, item.Childrens[i - 1].WorkingRectangle.Bottom, item.WorkingRectangle.Width - (item.DrawRectangle.Width + splitWidth), child.AllChildrensMaxShowHeight); } DrawItem(child, g); } } //连线 if (item.ParentItem != null) { g.DrawLines(new Pen(new SolidBrush(lineColor), 1), new PointF[] { new PointF(item.ParentItem.DrawRectangle.Right, item.ParentItem.DrawRectangle.Top + item.ParentItem.DrawRectangle.Height / 2), new PointF(item.ParentItem.DrawRectangle.Right + 12, item.ParentItem.DrawRectangle.Top + item.ParentItem.DrawRectangle.Height / 2), //new PointF(item.ParentItem.DrawRectangle.Right+12,item.DrawRectangle.Top+item.DrawRectangle.Height/2), new PointF(item.DrawRectangle.Left - 12, item.DrawRectangle.Top + item.DrawRectangle.Height / 2), new PointF(item.DrawRectangle.Left, item.DrawRectangle.Top + item.DrawRectangle.Height / 2), }); } //展开折叠按钮 if (item.Childrens != null && item.Childrens.Length > 0) { RectangleF _rect = new RectangleF(item.DrawRectangle.Right + 1, item.DrawRectangle.Top + (item.DrawRectangle.Height - 10) / 2, 10, 10); item.ExpansionRectangle = _rect; g.FillEllipse(new SolidBrush(this.BackColor), _rect); g.DrawEllipse(new Pen(new SolidBrush(Color.Black)), _rect); g.DrawLine(new Pen(new SolidBrush(lineColor)), _rect.Left + 2, _rect.Y + _rect.Height / 2, _rect.Right - 2, _rect.Y + _rect.Height / 2); if (!item.IsExpansion) { g.DrawLine(new Pen(new SolidBrush(lineColor)), _rect.Left + _rect.Width / 2, _rect.Top + 2, _rect.Left + _rect.Width / 2, _rect.Bottom - 2); } } }