C# winfrom DEV左侧菜单栏DIY

C# winfrom DEV左侧菜单栏DIY_第1张图片虽然DEV控件提供了navBarControl控件作为左侧菜单栏,但是对于各种需求面前仅仅也是鸡肋...只能新增分组..集合...虽然在ViewChooser里面提供了多种风格。然并无拓展性...

进入主题....

首先添加splitContainerControl然后在panel2中添加flowLayoutPanel,再flowLayoutPanel中添加两个simpleButton和两个panelControl如图所示:C# winfrom DEV左侧菜单栏DIY_第2张图片

好了接下来就贴代码,在构造函数中添加如下代码C# winfrom DEV左侧菜单栏DIY_第3张图片

然后~~写两个方法:

        private void leftMenu()
        {
            simpleButton2.Tag = simpleButton1.Tag = 1;
            panelControl1.Visible = panelControl10.Visible  = false;
        }
        private void btn_Click(object sender, EventArgs e)
        {
            SimpleButton btn = sender as SimpleButton;
            foreach (Control x in this.flowLayoutPanel1.Controls)
            {
                if (x.Name == "panelControl" + btn.Name[btn.Name.Length - 1])
                {
                    if ((int)btn.Tag == 2)
                    {
                        btn.Tag = 1;
                        x.Visible = false;
                        return;
                    }
                    else
                    {
                        btn.Tag = 2;
                        x.Visible = true;
                    }
                    break;
                }
            }
            int tmpUp = Convert.ToInt32(btn.Name[btn.Name.Length - 1].ToString()) - 1;
            int tmpDown = Convert.ToInt32(btn.Name[btn.Name.Length - 1].ToString()) + 1;

            foreach (Control x in this.flowLayoutPanel1.Controls)
            {
                if (tmpUp != 1)
                {
                    if (x.Name == "panelControl" + tmpUp) x.Visible = false;
                    if (x.Name == "SimpleButton" + tmpUp) x.Tag = 1;
                }
                if (x.Name == "panelControl" + tmpDown) x.Visible = false;
                if (x.Name == "SimpleButton" + tmpDown) x.Tag = 1;
            }
        }

OK!搞定!

 

你可能感兴趣的:(IT)