private TreeListHitTestInfo HitTestCell(VirtualTreeListItem vitem, Rectangle rect, int x, int y) { var workRect = _bound.ItemBound; var x1 = workRect.X - GetOffsetLeft(); var item = (TreeListItem)vitem.Item; foreach (var column in Columns) { if (column.Index > item.Cells.Count) { return(null); } if (column.Hidden) { continue; } var rect1 = new Rectangle(x1, rect.Y, column.Width, ItemHeight); if (rect1.Contains(x, y)) { var owner = new TreeListHitTestInfo(TreeListHitTestType.Item, vitem, rect); if (column.Index <= item.Cells.Count - 1) { return(new TreeListHitTestInfo(TreeListHitTestType.Cell, item.Cells[column.Index], rect1) { Owner = owner }); } else { return(owner); } } x1 += column.Width; } return(null); }
/// <summary> /// 提供座标 x 和 y 处的复选框信息。 /// </summary> /// <param name="item"></param> /// <param name="rect"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> private TreeListHitTestInfo HitTestItemCheckbox(VirtualTreeListItem item, Rectangle rect, int x, int y) { if (ShowCheckBoxes) { var sitem = (TreeListItem)item.Item; //如果项不可用,则单选按钮不可用 if (!sitem.Enabled || !sitem.ShowBox) { return(null); } var x1 = rect.Left + sitem.Level * Indent; //复选框区域 var mrect = new Rectangle(x1, rect.Top, 15, ItemHeight).Middle(15, 15); if (ShowPlusMinus) { mrect.Offset(16, 0); } //获取第一列的区域 var firstColumn = GetFirstColumn(); var crect = GetColumnBound(firstColumn); //获取当前Cell的区域 var srect = new Rectangle(crect.X, rect.Top, crect.Width, ItemHeight); if (mrect.Contains(x, y) && srect.IntersectsWith(mrect)) { return(new TreeListHitTestInfo(TreeListHitTestType.Checkbox, item, mrect)); } } return(null); }