主界面左侧菜单相关
This commit is contained in:
@@ -328,6 +328,7 @@ namespace Lskj.Business
|
||||
Instance.EnableSpecialInfoProcess = item.Table.Columns.Contains("EnableSpecialInfoProcess") && !string.IsNullOrEmpty(item["EnableSpecialInfoProcess"] + "") ? "1".Equals(item["EnableSpecialInfoProcess"] + "") : false;
|
||||
Instance.SourceFilteringMobile = item.Table.Columns.Contains("SourceFilteringMobile") && !string.IsNullOrEmpty(item["SourceFilteringMobile"] + "") ? "1".Equals(item["SourceFilteringMobile"] + "") : false;
|
||||
Instance.LoginUsername = item.Table.Columns.Contains("LoginUsername") && !string.IsNullOrEmpty(item["LoginUsername"] + "") ? item["LoginUsername"] + "" : "";
|
||||
Instance.MainLeftShowMode = item.Table.Columns.Contains("MainLeftShowMode") && !string.IsNullOrEmpty(item["MainLeftShowMode"] + "") ? item["MainLeftShowMode"] + "" : "";
|
||||
}
|
||||
/// <summary>
|
||||
/// 高拍仪AccessKey
|
||||
@@ -1144,6 +1145,10 @@ namespace Lskj.Business
|
||||
///登录界面,用户名显示字段
|
||||
/// </summary>
|
||||
public string LoginUsername;
|
||||
/// <summary>
|
||||
/// 主界面左侧树展示模式
|
||||
/// </summary>
|
||||
public string MainLeftShowMode;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ namespace Lskj.Main.Control
|
||||
{
|
||||
this.SetMenus();
|
||||
this.SetSearchMenus();
|
||||
if (!this._allMenus.Columns.Contains("groupcaption") || isFlowLayout)
|
||||
if (!CanUseLeftGroupTreeMenu())
|
||||
{
|
||||
this.tv_left.Visible = false;
|
||||
}
|
||||
@@ -803,6 +803,26 @@ namespace Lskj.Main.Control
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanUseLeftGroupTreeMenu()
|
||||
{
|
||||
return "1".Equals((SystemInfo.Instance.MainLeftShowMode + "").Trim()) && this._allMenus.Columns.Contains("groupcaption") && !isFlowLayout;
|
||||
}
|
||||
|
||||
private void ResetLeftMenuBarPanel()
|
||||
{
|
||||
SetLeftGroupSeparatorVisible(false);
|
||||
this.pl_center_left.Padding = new Padding(4);
|
||||
this.pl_center_left.BackColor = Color.FromArgb(10, 87, 167);
|
||||
if (_leftGroupTreeView != null && this.pl_center_left.Controls.Contains(_leftGroupTreeView))
|
||||
{
|
||||
this.pl_center_left.Controls.Remove(_leftGroupTreeView);
|
||||
}
|
||||
if (this.pl_center_left.Controls.Contains(this.tv_left))
|
||||
{
|
||||
this.tv_left.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private ImageList GetLeftGroupTreeIcons()
|
||||
{
|
||||
if (_leftGroupTreeIcons != null) return _leftGroupTreeIcons;
|
||||
@@ -1083,7 +1103,11 @@ namespace Lskj.Main.Control
|
||||
List<DataRow> rows = this._allMenus.AsEnumerable().Where(n => (n["subsysid"] + "").Equals(ERPInfo.Instance.SubSysId) && !string.IsNullOrEmpty(n["menustruct"] + "")).ToList();
|
||||
if (rows != null && rows.Count > 0)
|
||||
{
|
||||
bool useLeftGroupTreeMenu = this._allMenus.Columns.Contains("groupcaption") && !isFlowLayout;
|
||||
bool useLeftGroupTreeMenu = CanUseLeftGroupTreeMenu();
|
||||
if (!useLeftGroupTreeMenu)
|
||||
{
|
||||
ResetLeftMenuBarPanel();
|
||||
}
|
||||
DataTable leftGroupTreeTable = useLeftGroupTreeMenu ? CreateLeftGroupTreeTable() : null;
|
||||
int buttonTop = Convert.ToInt32(0.05 * DpiY); // 按钮上边距
|
||||
int menuLeft = Convert.ToInt32(0.05 * DpiY), menuTop = Convert.ToInt32(0.05 * DpiY); // 模块距离左边距,模块距离顶部边距
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Lskj.Main.Control
|
||||
{
|
||||
public partial class TreeViewCustom : UserControl
|
||||
{
|
||||
#region 公有属性
|
||||
#region 公有属性
|
||||
/// <summary>
|
||||
/// 父节点字段
|
||||
/// </summary>
|
||||
@@ -43,6 +43,30 @@ namespace Lskj.Main.Control
|
||||
/// 左侧菜单事件注册
|
||||
/// </summary>
|
||||
public ButtonClickEventHandler OnButtonClickEvent;
|
||||
/// <summary>
|
||||
/// 所有节点点击时都触发回调,默认保持原来的末级节点触发逻辑。
|
||||
/// </summary>
|
||||
public bool RaiseClickEventOnAllNodes;
|
||||
/// <summary>
|
||||
/// 默认显示所有节点。
|
||||
/// </summary>
|
||||
public bool ExpandAllNodes;
|
||||
/// <summary>
|
||||
/// 是否允许点击节点时展开/折叠子节点。
|
||||
/// </summary>
|
||||
public bool AllowNodeCollapse = true;
|
||||
/// <summary>
|
||||
/// 鼠标滑过节点时是否触发点击回调。
|
||||
/// </summary>
|
||||
public bool SwitchOnMouseMove;
|
||||
/// <summary>
|
||||
/// 使用旧版左侧菜单文字大小。
|
||||
/// </summary>
|
||||
public bool UseMenuBarTextStyle;
|
||||
/// <summary>
|
||||
/// 使用分组左侧菜单专用图片样式。
|
||||
/// </summary>
|
||||
public bool UseGroupTreeImageStyle;
|
||||
#endregion
|
||||
|
||||
#region 私有属性
|
||||
@@ -65,6 +89,14 @@ namespace Lskj.Main.Control
|
||||
/// 缓存所有按钮
|
||||
/// </summary>
|
||||
private Dictionary<string, Button> _dicButtons = new Dictionary<string, Button>();
|
||||
/// <summary>
|
||||
/// 记录节点自身是否应显示,避免 Control.Visible 受父控件可见性影响。
|
||||
/// </summary>
|
||||
private HashSet<string> _visibleNodeValues = new HashSet<string>();
|
||||
/// <summary>
|
||||
/// 默认展开节点。
|
||||
/// </summary>
|
||||
private string _defaultExpandNodeValue;
|
||||
#endregion
|
||||
|
||||
#region Api
|
||||
@@ -108,6 +140,7 @@ namespace Lskj.Main.Control
|
||||
public TreeViewCustom()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.plTreeView.Resize += (s, e) => ReflowTreeNodes();
|
||||
}
|
||||
|
||||
protected override void WndProc(ref Message m)
|
||||
@@ -154,38 +187,41 @@ namespace Lskj.Main.Control
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
public void SetDataSource(DataTable dtTable)
|
||||
{
|
||||
SetDataSource(dtTable, string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载菜单并展开默认节点。
|
||||
/// </summary>
|
||||
public void SetDataSource(DataTable dtTable, string defaultExpandNodeValue)
|
||||
{
|
||||
int index = 1;
|
||||
this._dataSource = dtTable;
|
||||
this._lastTreeNode = null;
|
||||
this._lastMenuId = null;
|
||||
this._defaultExpandNodeValue = defaultExpandNodeValue;
|
||||
this._dicTreeNodes.Clear();
|
||||
this._dicButtons.Clear();
|
||||
this._visibleNodeValues.Clear();
|
||||
this.plTreeView.Controls.Clear();
|
||||
if (_dataSource == null || _dataSource.Rows.Count == 0) return;
|
||||
|
||||
// 获取根节点
|
||||
DataRow[] rootRows = _dataSource.Rows.Cast<DataRow>().Where(x => (x[ParentField] + "").Length == ParentKeyLength || (x[ParentField] + "").Length == ParentKeyLength * 2).ToArray();
|
||||
foreach (DataRow item in _dataSource.Rows)
|
||||
var leftItems = _dataSource.Rows.Cast<DataRow>().OrderBy(n => n[ParentField] + "");
|
||||
foreach (DataRow item in leftItems)
|
||||
{
|
||||
int length = (item[ParentField] + "").Length;
|
||||
string nodeValue = item[ParentField] + "";
|
||||
int length = nodeValue.Length;
|
||||
TreeNodeCustom treeNode = new TreeNodeCustom();
|
||||
treeNode.Dock = DockStyle.Top;
|
||||
treeNode.Tag = item[ParentField] + "";
|
||||
treeNode.Dock = DockStyle.None;
|
||||
treeNode.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
|
||||
treeNode.Tag = nodeValue;
|
||||
treeNode.TabIndex = index;
|
||||
if (UseMenuBarTextStyle)
|
||||
{
|
||||
treeNode.Height = 44;
|
||||
}
|
||||
|
||||
if (length == ParentKeyLength)
|
||||
{
|
||||
treeNode.btnTreeNode.BackgroundImage = Lskj.Main.Properties.Resources.node_default;
|
||||
treeNode.btnTreeNode.Font = new Font("微软雅黑", 12);
|
||||
}
|
||||
else if (length / ParentKeyLength == 2)
|
||||
{
|
||||
treeNode.btnTreeNode.BackgroundImage = Lskj.Main.Properties.Resources.node2_default;
|
||||
treeNode.btnTreeNode.Padding = new Padding(20, 1, 3, 3);
|
||||
treeNode.btnTreeNode.Font = new Font("微软雅黑", 11);
|
||||
}
|
||||
else
|
||||
{
|
||||
treeNode.btnTreeNode.BackgroundImage = Lskj.Main.Properties.Resources.node3_default;
|
||||
treeNode.btnTreeNode.Padding = new Padding(30, 1, 3, 3);
|
||||
treeNode.btnTreeNode.Font = new Font("微软雅黑", 10);
|
||||
}
|
||||
SetNodeDefaultStyle(treeNode.btnTreeNode, GetNodeLevel(nodeValue));
|
||||
|
||||
treeNode.btnTreeNode.Name = index + "";
|
||||
treeNode.btnTreeNode.Text = item[TextField] + "";
|
||||
@@ -197,12 +233,322 @@ namespace Lskj.Main.Control
|
||||
plTreeView.Controls.Add(treeNode);
|
||||
_dicButtons.Add(index + "", treeNode.btnTreeNode);
|
||||
|
||||
List<TreeNodeCustom> parentNodes = getParentNodes(item[ParentField] + "");
|
||||
List<TreeNodeCustom> parentNodes = getParentNodes(nodeValue);
|
||||
parentNodes.Add(treeNode);
|
||||
// 隐藏需要放在添加后,否则出现顺序错乱
|
||||
treeNode.Visible = length == ParentKeyLength;
|
||||
SetNodeVisibleState(treeNode, ExpandAllNodes || length == ParentKeyLength || IsDefaultExpandedChildNode(nodeValue));
|
||||
index++;
|
||||
}
|
||||
RefreshNodeStyles();
|
||||
ReflowTreeNodes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 展开指定节点。
|
||||
/// </summary>
|
||||
public void ExpandNode(string nodeValue)
|
||||
{
|
||||
if (string.IsNullOrEmpty(nodeValue)) return;
|
||||
|
||||
foreach (TreeNodeCustom node in plTreeView.Controls.OfType<TreeNodeCustom>())
|
||||
{
|
||||
string menuKey = node.Tag + "";
|
||||
if (menuKey.Length <= nodeValue.Length || !menuKey.StartsWith(nodeValue)) continue;
|
||||
SetNodeVisibleState(node, true);
|
||||
}
|
||||
RefreshNodeStyles();
|
||||
ReflowTreeNodes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中指定节点,仅更新样式,不触发业务回调。
|
||||
/// </summary>
|
||||
public void SelectNode(string nodeValue)
|
||||
{
|
||||
if (string.IsNullOrEmpty(nodeValue)) return;
|
||||
|
||||
TreeNodeCustom treeNode = plTreeView.Controls.OfType<TreeNodeCustom>().FirstOrDefault(n => (n.Tag + "").Equals(nodeValue));
|
||||
if (treeNode == null) return;
|
||||
|
||||
SelectNodeButton(treeNode.btnTreeNode, nodeValue);
|
||||
}
|
||||
|
||||
private int GetNodeLevel(string nodeValue)
|
||||
{
|
||||
if (ParentKeyLength <= 0 || string.IsNullOrEmpty(nodeValue)) return 1;
|
||||
return Math.Max(1, nodeValue.Length / ParentKeyLength);
|
||||
}
|
||||
|
||||
private int GetVisualNodeLevel(string nodeValue)
|
||||
{
|
||||
return GetNodeLevel(nodeValue);
|
||||
}
|
||||
|
||||
private bool IsDefaultExpandedChildNode(string nodeValue)
|
||||
{
|
||||
return !string.IsNullOrEmpty(_defaultExpandNodeValue)
|
||||
&& nodeValue.Length > _defaultExpandNodeValue.Length
|
||||
&& nodeValue.StartsWith(_defaultExpandNodeValue);
|
||||
}
|
||||
|
||||
private void SetNodeVisibleState(TreeNodeCustom node, bool visible)
|
||||
{
|
||||
if (node == null) return;
|
||||
|
||||
string nodeValue = node.Tag + "";
|
||||
if (visible)
|
||||
{
|
||||
_visibleNodeValues.Add(nodeValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
_visibleNodeValues.Remove(nodeValue);
|
||||
}
|
||||
node.Visible = visible;
|
||||
}
|
||||
|
||||
private bool GetNodeVisibleState(TreeNodeCustom node)
|
||||
{
|
||||
if (node == null) return false;
|
||||
|
||||
return _visibleNodeValues.Contains(node.Tag + "");
|
||||
}
|
||||
|
||||
private void RefreshNodeStyles()
|
||||
{
|
||||
foreach (TreeNodeCustom node in plTreeView.Controls.OfType<TreeNodeCustom>())
|
||||
{
|
||||
string nodeValue = node.Tag + "";
|
||||
SetNodeDefaultStyle(node.btnTreeNode, GetVisualNodeLevel(nodeValue));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_lastMenuId) && _dicButtons.ContainsKey(_lastMenuId))
|
||||
{
|
||||
Button button = _dicButtons[_lastMenuId];
|
||||
TreeNodeCustom treeNode = button.Parent as TreeNodeCustom;
|
||||
SetNodeSelectImage(button, GetVisualNodeLevel(treeNode == null ? string.Empty : treeNode.Tag + ""));
|
||||
}
|
||||
}
|
||||
|
||||
private void ReflowTreeNodes()
|
||||
{
|
||||
if (plTreeView == null) return;
|
||||
|
||||
int top = 0;
|
||||
int width = Math.Max(0, plTreeView.ClientSize.Width);
|
||||
var parNodes = plTreeView.Controls.OfType<TreeNodeCustom>().OrderBy(n => n.TabIndex);
|
||||
foreach (TreeNodeCustom node in parNodes)
|
||||
{
|
||||
node.Width = width;
|
||||
node.Left = 0;
|
||||
node.Top = top;
|
||||
if (!GetNodeVisibleState(node)) continue;
|
||||
|
||||
top += node.Height;
|
||||
}
|
||||
plTreeView.AutoScrollMinSize = new Size(0, top);
|
||||
}
|
||||
|
||||
private bool HasChildNodes(string nodeValue)
|
||||
{
|
||||
if (string.IsNullOrEmpty(nodeValue) || !_dicTreeNodes.ContainsKey(nodeValue)) return false;
|
||||
return _dicTreeNodes[nodeValue].Any(n => (n.Tag + "").Length > nodeValue.Length);
|
||||
}
|
||||
|
||||
private bool HasVisibleChildNodes(string nodeValue)
|
||||
{
|
||||
if (string.IsNullOrEmpty(nodeValue) || !_dicTreeNodes.ContainsKey(nodeValue)) return false;
|
||||
return _dicTreeNodes[nodeValue].Any(n => (n.Tag + "").Length > nodeValue.Length && GetNodeVisibleState(n));
|
||||
}
|
||||
|
||||
private Image GetGroupTreeDefaultImage(int nodeLevel)
|
||||
{
|
||||
if (nodeLevel <= 1) return Lskj.Main.Properties.Resources.tree_group_l1_default;
|
||||
if (nodeLevel == 2) return Lskj.Main.Properties.Resources.tree_group_l2_default;
|
||||
return Lskj.Main.Properties.Resources.tree_group_l3_default;
|
||||
}
|
||||
|
||||
private Image GetGroupTreeMoveImage(int nodeLevel)
|
||||
{
|
||||
if (nodeLevel <= 1) return Lskj.Main.Properties.Resources.tree_group_l1_move;
|
||||
if (nodeLevel == 2) return Lskj.Main.Properties.Resources.tree_group_l2_move;
|
||||
return Lskj.Main.Properties.Resources.tree_group_l3_move;
|
||||
}
|
||||
|
||||
private Image GetGroupTreeSelectImage(int nodeLevel)
|
||||
{
|
||||
if (nodeLevel <= 1) return Lskj.Main.Properties.Resources.tree_group_l1_select;
|
||||
if (nodeLevel == 2) return Lskj.Main.Properties.Resources.tree_group_l2_select;
|
||||
return Lskj.Main.Properties.Resources.tree_group_l3_select;
|
||||
}
|
||||
|
||||
private void SetNodeDefaultStyle(Button button, int nodeLevel)
|
||||
{
|
||||
if (button == null) return;
|
||||
|
||||
if (UseGroupTreeImageStyle)
|
||||
{
|
||||
button.BackgroundImage = GetGroupTreeDefaultImage(nodeLevel);
|
||||
button.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
button.Image = null;
|
||||
button.TextImageRelation = TextImageRelation.Overlay;
|
||||
button.TabStop = false;
|
||||
button.FlatAppearance.BorderSize = 0;
|
||||
button.FlatAppearance.MouseDownBackColor = Color.Transparent;
|
||||
button.FlatAppearance.MouseOverBackColor = Color.Transparent;
|
||||
button.Padding = new Padding(34 + Math.Max(0, nodeLevel - 1) * 12, 0, 3, 0);
|
||||
button.Font = new Font("微软雅黑", 12);
|
||||
button.TextAlign = ContentAlignment.MiddleLeft;
|
||||
return;
|
||||
}
|
||||
|
||||
if (UseMenuBarTextStyle)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.left_default;
|
||||
button.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
button.Image = null;
|
||||
button.TextImageRelation = TextImageRelation.Overlay;
|
||||
button.Font = new Font("微软雅黑", 10);
|
||||
button.Padding = new Padding(20 + Math.Max(0, nodeLevel - 1) * 20, 3, 3, 3);
|
||||
button.TextAlign = ContentAlignment.MiddleLeft;
|
||||
return;
|
||||
}
|
||||
|
||||
if (nodeLevel <= 1)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node_default;
|
||||
button.Image = null;
|
||||
button.Padding = new Padding(10, 0, 0, 0);
|
||||
button.Font = new Font("微软雅黑", 12);
|
||||
}
|
||||
else if (nodeLevel == 2)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node2_default;
|
||||
button.Image = null;
|
||||
button.Padding = new Padding(20, 1, 3, 3);
|
||||
button.Font = new Font("微软雅黑", 11);
|
||||
}
|
||||
else
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node3_default;
|
||||
button.Image = null;
|
||||
button.Padding = new Padding(30 + Math.Max(0, nodeLevel - 3) * 10, 1, 3, 3);
|
||||
button.Font = new Font("微软雅黑", 10);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetNodeDefaultImage(Button button, int nodeLevel)
|
||||
{
|
||||
if (button == null) return;
|
||||
|
||||
if (UseGroupTreeImageStyle)
|
||||
{
|
||||
button.BackgroundImage = GetGroupTreeDefaultImage(nodeLevel);
|
||||
return;
|
||||
}
|
||||
|
||||
if (UseMenuBarTextStyle)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.left_default;
|
||||
return;
|
||||
}
|
||||
|
||||
if (nodeLevel <= 1)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node_default;
|
||||
}
|
||||
else if (nodeLevel == 2)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node2_default;
|
||||
}
|
||||
else
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node3_default;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetNodeSelectImage(Button button, int nodeLevel)
|
||||
{
|
||||
if (button == null) return;
|
||||
|
||||
if (UseGroupTreeImageStyle)
|
||||
{
|
||||
button.BackgroundImage = GetGroupTreeSelectImage(nodeLevel);
|
||||
return;
|
||||
}
|
||||
|
||||
if (UseMenuBarTextStyle)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.left_select;
|
||||
return;
|
||||
}
|
||||
|
||||
if (nodeLevel <= 1)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node_select;
|
||||
}
|
||||
else if (nodeLevel == 2)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node2_select;
|
||||
}
|
||||
else
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node3_select;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetNodeMoveImage(Button button, int nodeLevel)
|
||||
{
|
||||
if (button == null) return;
|
||||
|
||||
if (UseGroupTreeImageStyle)
|
||||
{
|
||||
button.BackgroundImage = GetGroupTreeMoveImage(nodeLevel);
|
||||
return;
|
||||
}
|
||||
|
||||
if (UseMenuBarTextStyle)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.left_select;
|
||||
return;
|
||||
}
|
||||
|
||||
if (nodeLevel <= 1)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node_select;
|
||||
}
|
||||
else if (nodeLevel == 2)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node2_move;
|
||||
}
|
||||
else
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node3_move;
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectNodeButton(Button button, string nodeValue)
|
||||
{
|
||||
if (button == null) return;
|
||||
|
||||
if (!string.IsNullOrEmpty(_lastMenuId) && _lastMenuId != button.Name && _dicButtons.ContainsKey(_lastMenuId))
|
||||
{
|
||||
Button lastButton = _dicButtons[_lastMenuId];
|
||||
TreeNodeCustom lastNode = lastButton.Parent as TreeNodeCustom;
|
||||
SetNodeDefaultImage(lastButton, GetVisualNodeLevel(lastNode == null ? string.Empty : lastNode.Tag + ""));
|
||||
}
|
||||
|
||||
SetNodeSelectImage(button, GetVisualNodeLevel(nodeValue));
|
||||
_lastMenuId = button.Name;
|
||||
}
|
||||
|
||||
private void TriggerNodeEvent(Button button, string nodeValue)
|
||||
{
|
||||
SelectNodeButton(button, nodeValue);
|
||||
if (OnButtonClickEvent != null)
|
||||
{
|
||||
this.OnButtonClickEvent(button);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:树点击</para>
|
||||
@@ -226,54 +572,47 @@ namespace Lskj.Main.Control
|
||||
{
|
||||
_lastTreeNode = nodeValue;
|
||||
}
|
||||
if (nodeValue.Length == ParentKeyLength)
|
||||
{
|
||||
treeNode.btnTreeNode.BackgroundImage = _dicTreeNodes[nodeValue][0].Visible ? Lskj.Main.Properties.Resources.node_default : Lskj.Main.Properties.Resources.node_select;
|
||||
}
|
||||
if (nodeValue.Length == ParentKeyLength * 2)
|
||||
{
|
||||
treeNode.btnTreeNode.BackgroundImage = _dicTreeNodes[nodeValue][0].Visible ? Lskj.Main.Properties.Resources.node2_default : Lskj.Main.Properties.Resources.node2_select;
|
||||
}
|
||||
// 末节点
|
||||
if (nodeValue.Length == ParentKeyLength * 3)
|
||||
{
|
||||
treeNode.btnTreeNode.BackgroundImage = Lskj.Main.Properties.Resources.node3_select;
|
||||
if (!string.IsNullOrEmpty(_lastMenuId) && _lastMenuId != treeNode.btnTreeNode.Name)
|
||||
{
|
||||
_dicButtons[_lastMenuId].BackgroundImage = Lskj.Main.Properties.Resources.node3_default;
|
||||
}
|
||||
_lastMenuId = treeNode.btnTreeNode.Name;
|
||||
}
|
||||
int nodeLevel = GetVisualNodeLevel(nodeValue);
|
||||
bool hasChildNodes = HasChildNodes(nodeValue);
|
||||
List<TreeNodeCustom> treeNodes = new List<TreeNodeCustom>();
|
||||
// 展开当前点击节点
|
||||
if (_dicTreeNodes.ContainsKey(nodeValue))
|
||||
if (hasChildNodes && AllowNodeCollapse)
|
||||
{
|
||||
treeNodes = _dicTreeNodes[nodeValue];
|
||||
foreach (TreeNodeCustom node in treeNodes)
|
||||
{
|
||||
string menuKey = node.Tag + "";
|
||||
if (menuKey.Length == ParentKeyLength) continue;
|
||||
node.Visible = !node.Visible;
|
||||
Application.DoEvents();// 处理当前消息队列中的所有windows消息
|
||||
if (menuKey.Length <= nodeValue.Length) continue;
|
||||
SetNodeVisibleState(node, !GetNodeVisibleState(node));
|
||||
}
|
||||
ReflowTreeNodes();
|
||||
if (!RaiseClickEventOnAllNodes)
|
||||
{
|
||||
if (HasVisibleChildNodes(nodeValue))
|
||||
{
|
||||
SetNodeSelectImage(treeNode.btnTreeNode, nodeLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetNodeDefaultImage(treeNode.btnTreeNode, nodeLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 点击根节点隐藏所有子节点
|
||||
if (nodeValue.Length == ParentKeyLength && !_dicTreeNodes[nodeValue][0].Visible)
|
||||
if (AllowNodeCollapse && nodeValue.Length == ParentKeyLength && !HasVisibleChildNodes(nodeValue))
|
||||
{
|
||||
treeNodes = getChildNodes(nodeValue);
|
||||
foreach (TreeNodeCustom node in treeNodes)
|
||||
{
|
||||
node.Visible = false;
|
||||
SetNodeVisibleState(node, false);
|
||||
//Application.DoEvents();// 处理当前消息队列中的所有windows消息
|
||||
}
|
||||
ReflowTreeNodes();
|
||||
}
|
||||
// 点击末节点
|
||||
if (nodeValue.Length == ParentKeyLength * 3)
|
||||
if (RaiseClickEventOnAllNodes || nodeValue.Length == ParentKeyLength * 3)
|
||||
{
|
||||
if (OnButtonClickEvent != null)
|
||||
{
|
||||
this.OnButtonClickEvent(treeNode.btnTreeNode);
|
||||
}
|
||||
TriggerNodeEvent(treeNode.btnTreeNode, nodeValue);
|
||||
}
|
||||
_lastTreeNode = nodeValue;
|
||||
}
|
||||
@@ -303,15 +642,34 @@ namespace Lskj.Main.Control
|
||||
|
||||
TreeNodeCustom treeNode = button.Parent as TreeNodeCustom;
|
||||
string treeNodeTag = treeNode.Tag + "";
|
||||
if (treeNodeTag.Length == ParentKeyLength)
|
||||
int nodeLevel = GetVisualNodeLevel(treeNodeTag);
|
||||
if (SwitchOnMouseMove && button.Name != _lastMenuId)
|
||||
{
|
||||
TriggerNodeEvent(button, treeNodeTag);
|
||||
if (!UseGroupTreeImageStyle)
|
||||
{
|
||||
SetNodeMoveImage(button, nodeLevel);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (treeNodeTag.Length == ParentKeyLength * 2)
|
||||
|
||||
if (button.Name == _lastMenuId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (UseGroupTreeImageStyle)
|
||||
{
|
||||
SetNodeMoveImage(button, nodeLevel);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nodeLevel == 2)
|
||||
{
|
||||
// 第一级节点
|
||||
if (_dicTreeNodes.ContainsKey(treeNodeTag) && _dicTreeNodes[treeNodeTag].Count > 0)
|
||||
if (HasChildNodes(treeNodeTag))
|
||||
{
|
||||
button.BackgroundImage = _dicTreeNodes[treeNodeTag][0].Visible ? Lskj.Main.Properties.Resources.node2_select : Lskj.Main.Properties.Resources.node2_move;
|
||||
button.BackgroundImage = HasVisibleChildNodes(treeNodeTag) ? Lskj.Main.Properties.Resources.node2_select : Lskj.Main.Properties.Resources.node2_move;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -321,10 +679,7 @@ namespace Lskj.Main.Control
|
||||
else
|
||||
{
|
||||
// 末节点
|
||||
if (button.Name != _lastMenuId)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node3_move;
|
||||
}
|
||||
SetNodeMoveImage(button, nodeLevel);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -353,15 +708,24 @@ namespace Lskj.Main.Control
|
||||
|
||||
TreeNodeCustom treeNode = button.Parent as TreeNodeCustom;
|
||||
string treeNodeTag = treeNode.Tag + "";
|
||||
if (treeNodeTag.Length == ParentKeyLength)
|
||||
int nodeLevel = GetVisualNodeLevel(treeNodeTag);
|
||||
if (button.Name == _lastMenuId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (treeNodeTag.Length == ParentKeyLength * 2)
|
||||
|
||||
if (UseGroupTreeImageStyle)
|
||||
{
|
||||
SetNodeDefaultImage(button, nodeLevel);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nodeLevel == 2)
|
||||
{
|
||||
// 第一级节点
|
||||
if (_dicTreeNodes.ContainsKey(treeNodeTag) && _dicTreeNodes[treeNodeTag].Count > 0)
|
||||
if (HasChildNodes(treeNodeTag))
|
||||
{
|
||||
button.BackgroundImage = _dicTreeNodes[treeNodeTag][0].Visible ? Lskj.Main.Properties.Resources.node2_select : Lskj.Main.Properties.Resources.node2_default;
|
||||
button.BackgroundImage = HasVisibleChildNodes(treeNodeTag) ? Lskj.Main.Properties.Resources.node2_select : Lskj.Main.Properties.Resources.node2_default;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -371,10 +735,7 @@ namespace Lskj.Main.Control
|
||||
else
|
||||
{
|
||||
// 末节点
|
||||
if (button.Name != _lastMenuId)
|
||||
{
|
||||
button.BackgroundImage = Lskj.Main.Properties.Resources.node3_default;
|
||||
}
|
||||
SetNodeDefaultImage(button, nodeLevel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user