*UITreeView: 判断节点Checked是否改变,只有改变时才赋值

This commit is contained in:
Sunny 2021-10-12 11:15:37 +08:00
parent 904aa0bb9e
commit abdfd501cb
3 changed files with 35 additions and 30 deletions

Binary file not shown.

Binary file not shown.

View File

@ -740,9 +740,9 @@ namespace Sunny.UI
} }
else else
{ {
var drawOffsetX = e.Node.Bounds.X-57-e.Node.Level * Indent;
var drawLeft = (e.Node.Level + 1) * Indent + 3+ drawOffsetX; var drawLeft = (e.Node.Level + 1) * Indent + 3;
var checkBoxLeft = (e.Node.Level + 1) * Indent + 1+ drawOffsetX; var checkBoxLeft = (e.Node.Level + 1) * Indent + 1;
var imageLeft = drawLeft; var imageLeft = drawLeft;
var haveImage = false; var haveImage = false;
var sf = e.Graphics.MeasureString(e.Node.Text, Font); var sf = e.Graphics.MeasureString(e.Node.Text, Font);
@ -802,6 +802,8 @@ namespace Sunny.UI
if (CheckBoxes) if (CheckBoxes)
{ {
if (!e.Node.Checked) if (!e.Node.Checked)
{ {
e.Graphics.DrawRectangle(checkboxColor, e.Graphics.DrawRectangle(checkboxColor,
@ -838,7 +840,7 @@ namespace Sunny.UI
} }
var lineY = e.Bounds.Y + e.Node.Bounds.Height / 2 - 1; var lineY = e.Bounds.Y + e.Node.Bounds.Height / 2 - 1;
var lineX = 3 + e.Node.Level * Indent + 9+drawOffsetX ; var lineX = 3 + e.Node.Level * Indent + 9;
if (ShowLinesEx) if (ShowLinesEx)
{ {
@ -892,7 +894,7 @@ namespace Sunny.UI
} }
} }
lineX = 3 + e.Node.Level * Indent + 9 + drawOffsetX; lineX = 3 + e.Node.Level * Indent + 9;
//绘制左侧+号 //绘制左侧+号
if (ShowPlusMinus && e.Node.Nodes.Count > 0) if (ShowPlusMinus && e.Node.Nodes.Count > 0)
{ {
@ -932,6 +934,7 @@ namespace Sunny.UI
protected override void OnAfterCheck(TreeViewEventArgs e) protected override void OnAfterCheck(TreeViewEventArgs e)
{ {
base.OnAfterCheck(e); base.OnAfterCheck(e);
if (e.Action == TreeViewAction.ByMouse) //鼠标点击 if (e.Action == TreeViewAction.ByMouse) //鼠标点击
{ {
@ -953,12 +956,14 @@ namespace Sunny.UI
TreeNode parentNode = currNode.Parent; //获得当前节点的父节点 TreeNode parentNode = currNode.Parent; //获得当前节点的父节点
var count = parentNode.Nodes.Cast<TreeNode>().Where(n => n.Checked).ToList().Count; var count = parentNode.Nodes.Cast<TreeNode>().Where(n => n.Checked).ToList().Count;
//判断节点Checked是否改变只有改变时才赋值否则不变更以防止频繁触发OnAfterCheck事件 //判断节点Checked是否改变只有改变时才赋值否则不变更以防止频繁触发OnAfterCheck事件
bool bChecked = count == parentNode.Nodes.Count; bool bChecked = count == parentNode.Nodes.Count;
if (parentNode.Checked != bChecked) if (parentNode.Checked != bChecked)
{ {
parentNode.Checked = bChecked; parentNode.Checked = bChecked;
} }
var half = parentNode.Nodes.Cast<TreeNode>().Where(n => (DicNodeStatus.ContainsKey(n.GetHashCode()) ? DicNodeStatus[n.GetHashCode()] : false)).ToList().Count; var half = parentNode.Nodes.Cast<TreeNode>().Where(n => (DicNodeStatus.ContainsKey(n.GetHashCode()) ? DicNodeStatus[n.GetHashCode()] : false)).ToList().Count;
if ((count > 0 && count < parentNode.Nodes.Count) || half > 0) if ((count > 0 && count < parentNode.Nodes.Count) || half > 0)