Пример #1
0
        /// <summary>
        ///     Adds sidebar menu.
        /// </summary>
        /// <param name="menuOptions">   Options for controlling the sidebar menu. </param>
        /// <param name="submenuButtonOptions"> Options for controlling the submenu buttons. </param>
        public void AddSidebarMenu(Sidebar.MenuOptions menuOptions,
                                   params Sidebar.ButtonOptions[] submenuButtonOptions)
        {
            Sidebar.Button menuBtn = _sidebar.InternalAdd(menuOptions);

            Sidebar menu = new Sidebar
            {
                Text      = menuOptions.Text,
                ForeColor = menuOptions.DefaultColor,
                Height    = submenuButtonOptions.Sum(s => s.IconSize + (s.IconSize / 2)) + 10,
                Dock      = DockStyle.Top,
                Padding   = new Padding(5, 5, 0, 0),
                BackColor = Color.FromArgb(21, 27, 37),
                Visible   = false
            };

            _sidebar.ItemClicked += (sender, args) =>
            {
                if (menuBtn == sender)
                {
                    menu.Visible = !menu.Visible;
                }
                else
                {
                    menu.Visible = false;
                    menu.Reset();
                }
            };

            _sidebar.Controls.Add(menu);
            _sidebar.Controls.SetChildIndex(menu, 0);
            foreach (Sidebar.ButtonOptions option in submenuButtonOptions)
            {
                Sidebar.Button btn = menu.InternalAdd(option);
                if (option.Click != null)
                {
                    btn.Click += option.Click;
                }
            }
        }