/// <summary> /// 设置一级菜单 /// </summary> /// <param name="parentPanel"></param> /// <param name="list"></param> public static void SetPanel(Panel parentPanel, List <KyoPanel> list) { parentPanel.BackColor = DEFAULT_BGCOLOR; for (int i = 0; i < list.Count; i++) { KyoPanel kyoPane = list[i]; Panel panel = new Panel { Width = parentPanel.Width, Height = DEFAULT_PANEL_HEIGHT, Name = kyoPane.Name, Left = 0, Top = i * DEFAULT_PANEL_HEIGHT - i, BorderStyle = BorderStyle.FixedSingle, Font = DEFAULT_LABEL_FONT, }; PictureBox box = new PictureBox { Image = kyoPane.Image, Height = DEFAULT_PIC_HEIGHT, Width = DEFAULT_PIC_WIDTH, Location = new Point(30, 22), SizeMode = PictureBoxSizeMode.StretchImage, BackColor = Color.Transparent, }; Label label = new Label { Text = kyoPane.Text, AutoSize = true, Location = new Point(80, 26), ForeColor = DEFAULT_LABEL_FORECOLOR }; if (kyoPane.HasNext) { Label arrow = new Label { Name = kyoPane.Name + "_ARROW", Text = "▲", ForeColor = Color.White, Location = new Point(207, 25), Size = new Size(22, 22), Font = new Font("微软雅黑", 10, FontStyle.Bold) }; arrow.MouseClick += Panel_MouseClick; panel.Controls.Add(arrow); } panel.MouseClick += Panel_MouseClick; box.MouseClick += Panel_MouseClick; label.MouseClick += Panel_MouseClick; panel.Controls.Add(box); panel.Controls.Add(label); parentPanel.Controls.Add(panel); } }
/// <summary> /// 创建二级菜单并展开 /// </summary> /// <param name="parentPanel">菜单所属父级</param> /// <param name="basicPanel">菜单容器</param> /// <param name="list">二级菜单列表</param> private static void ExpandSub(Panel parentPanel, Panel basicPanel, List <KyoPanel> list, Action <object, EventArgs> action) { Panel _panel = parentPanel.Parent as Panel; for (int i = 0; i < list.Count; i++) { KyoPanel kyoPanel = list[i]; Panel panel = new Panel { Width = basicPanel.Width, Height = DEFAULT_SUB_LABEL_HEIGHT, Left = 0, Top = i * DEFAULT_SUB_LABEL_HEIGHT, Name = kyoPanel.Name, }; panel.MouseEnter += Panel_MouseEnter; panel.Click += new EventHandler(action); panel.MouseLeave += new EventHandler(delegate(object sender, EventArgs args) { Panel _p = sender as Panel; if (_p.BackColor != Color.FromArgb(0, 120, 245)) { _p.BackColor = Color.Transparent; } }); basicPanel.Controls.Add(panel); Label _label = new Label { Text = kyoPanel.Text, ForeColor = Color.White, Location = new Point(77, 15), AutoSize = true }; panel.Controls.Add(_label); } _panel.Controls.Add(basicPanel); //将当前Panel下的所有选项板下移 foreach (Control item in _panel.Controls) { if (item != basicPanel) { if (item.Top > parentPanel.Top) { item.Top += basicPanel.Height; } } } Control[] cs = parentPanel.Controls.Find(parentPanel.Name + "_ARROW", false); if (cs.Length > 0) { cs[0].Text = "▼"; } }
/// <summary> /// 创建三级菜单并展开 /// </summary> /// <param name="parentPanel">菜单所属父级</param> /// <param name="basicPanel">菜单容器</param> /// <param name="list">三级菜单列表</param> private static void ExpandThree(Panel parentPanel, Panel basicPanel, List <KyoPanel> list, Action <object, EventArgs> click) { Panel _panel = parentPanel.Parent as Panel; for (int i = 0; i < list.Count; i++) { KyoPanel kyoPanel = list[i]; Panel panel = new Panel { Width = basicPanel.Width, Height = DEFAULT_SUB_LABEL_HEIGHT, Left = 0, Top = i * DEFAULT_SUB_LABEL_HEIGHT, Tag = false, Name = kyoPanel.Name, }; panel.Click += new EventHandler(click); basicPanel.Controls.Add(panel); Label _label = new Label { Text = kyoPanel.Text, ForeColor = Color.White, Location = new Point(77, 13), AutoSize = true }; if (kyoPanel.HasNext) { Label arrow = new Label { Name = panel.Name + "_ARROW", Text = "▲", ForeColor = Color.White, Location = new Point(207, 12), Size = new Size(22, 22), Font = new Font("微软雅黑", 10, FontStyle.Bold) }; arrow.Click += new EventHandler(click); panel.Controls.Add(arrow); } _label.Click += new EventHandler(click); panel.Controls.Add(_label); } _panel.Controls.Add(basicPanel); //将当前Panel下的所有选项板下移 foreach (Control item in _panel.Controls) { if (item != basicPanel) { if (item.Top > parentPanel.Top) { item.Top += basicPanel.Height; } } } Control[] cs = parentPanel.Controls.Find(parentPanel.Name + "_ARROW", false); if (cs.Length > 0) { cs[0].Text = "▼"; } }