Пример #1
0
        /// <summary>
        /// 子节点单点击事件,被点中状态
        /// </summary>
        private void ItemL_Childe_MouseClick(object sender, MouseEventArgs e)
        {
            Label label = sender as Label;
            INavigationBarOption option = label.Tag as INavigationBarOption;

            if (!childList.Contains(label.Parent as FlowLayoutPanel))
            {
                return;               //如果子项中不包含该控件,则退出
            }
            InitializaAllChildItem(); //初始化所有子节点
            label.Font      = new Font(_childItemFont.FontFamily, _childItemFont.Size + 1, FontStyle.Bold);
            label.ForeColor = _childSelectedForeColor;
        }
Пример #2
0
        /// <summary>
        /// 创建项中的控件
        /// </summary>
        /// <param name="option">项的设置信息</param>
        /// <param name="itemH">项高度</param>
        /// <param name="pPanel">项的父容器</param>
        /// <returns></returns>
        private FlowLayoutPanel CreatePanel(INavigationBarOption option, int itemH, FlowLayoutPanel pPanel, bool isChildNode)
        {
            CNavigationBar panel = new CNavigationBar();
            Label          itemL = new Label();

            panel.AutoScroll = false;
            panel.Height     = itemH;

            if (isChildNode)
            {
                panel.BackColor = _childBackColor;
                panel.Margin    = _childItemMargin;
                childList.Add(panel);
            }
            else
            {
                panel.BackColor = _parentBackColor;
                panel.Margin    = new Padding(0);
                parentList.Add(panel);
            }
            panel.Width = pPanel.Width;
            panel.Tag   = false;

            if (isChildNode)
            {
                itemL.Font = _childItemFont;
            }
            else
            {
                itemL.Font = _parentItemFont;
            }

            itemL.Text      = option.Title;
            itemL.TextAlign = ContentAlignment.MiddleCenter;
            itemL.BackColor = Color.Empty;
            itemL.ForeColor = this.ForeColor;
            itemL.Height    = panel.Height;
            itemL.Width     = panel.Width;
            itemL.Tag       = option;
            //添加鼠标进入与离开事件
            itemL.MouseEnter += ItemL_MouseEnter;
            itemL.MouseLeave += ItemL_MouseLeave;
            //如果该节点的子节点不为空,且子节点数大于0
            if (option.ChildItemsOption != null && option.ChildItemsOption.Count > 0)
            {
                itemL.Paint      += ItemL_Paint_Expand;      //添加展开与折叠图案绘制
                itemL.MouseClick += ItemL_Parent_MouseClick; //展开与折叠事件
                if (ParentItemMouseClick != null)
                {
                    itemL.MouseClick += ParentItemMouseClick;
                }
            }
            else
            {
                itemL.MouseClick += ItemL_Childe_MouseClick;//更改选中状态
                if (ChildItemMouseClick != null)
                {
                    itemL.MouseClick += ChildItemMouseClick;
                }
            }
            panel.Controls.Add(itemL);
            return(panel);
        }