/// <summary> /// Initialize the toolbar buttons. /// </summary> private void InitializeToolbarButtons() { toolbarButtons = new List <CCButton>(); prevToolbarButtons = new Stack <List <CCButton> >(); prevToolbarLabels = new Stack <string>(); prevToolbarIndex = new Stack <int>(); toolbarButtonsPanel = new DoubleBufferPanel(); toolbarButtonsPanel.Location = new Point(0, 0); toolbarButtonsPanel.Size = new Size(0, 50); toolbarButtonsPanel.AutoSize = true; toolbarButtonsPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; toolbarButtonsPanel.BackColor = this.toolbarColor;//Color.BlueViolet; //toolbarButtonsPanel.BackColor = Color.MidnightBlue; this.Controls.Add(toolbarButtonsPanel); SetToolbarButtonsPanelLocation(); }
/// <summary> /// Initialize and add the navigation buttons to the toolbar. /// </summary> private void InitializeNavButtons() { navButtonsPanel = new DoubleBufferPanel(); navButtonsPanel.AutoSize = true; navButtonsPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; navButtonsPanel.BackColor = this.toolbarColor;//Color.ForestGreen; //navButtonsPanel.BackColor = Color.MidnightBlue; this.Controls.Add(navButtonsPanel); SetNavButtonsPanelLocation(); prevCCBtn = new PrevCCButton(this); // ie: left / up nextCCBtn = new NextCCButton(this); // ie: right / down backCCBtn = new BackCCButton(this); settingsCCBtn = new SettingsCCButton(this); mainMenuCCBtn = new MainMenuCCButton(this); // Actually draw the buttons in the panel AddNavButtonsToPanel(); }
/// <summary> /// Add a list of buttons to the toolbar. /// </summary> /// <param name="buttons"></param> private void AddButtonsToToolbar(List <CCButton> buttons) { // Use a double-buffering like method // to reduce screen twitch when changing buttons // - create a copy of the toolbar panel to put the new buttons on DoubleBufferPanel tempPanel = new DoubleBufferPanel(); tempPanel.Location = toolbarButtonsPanel.Location; tempPanel.Size = toolbarButtonsPanel.Size; tempPanel.AutoSize = toolbarButtonsPanel.AutoSize; tempPanel.AutoSizeMode = toolbarButtonsPanel.AutoSizeMode; tempPanel.BackColor = toolbarButtonsPanel.BackColor; // Add new buttons to the copy panel for (int i = 0; i < buttons.Count; i++) { CCButton currentButton = buttons[i]; // Make sure button is the current desired size currentButton.Width = buttonWidth; currentButton.Height = buttonHeight; int x = 0; int y = 0; switch (this.orientation) { case ToolbarOrientation.HorizontalTop: x = i * (currentButton.Width + SPACE_BTWN_BTNS); y = 0; break; case ToolbarOrientation.HorizontalBottom: goto case ToolbarOrientation.HorizontalTop; case ToolbarOrientation.VerticalLeft: x = 0; y = i * (currentButton.Height + SPACE_BTWN_BTNS); break; case ToolbarOrientation.VerticalRight: goto case ToolbarOrientation.VerticalLeft; default: break; } currentButton.Location = new Point(x, y); tempPanel.Controls.Add(currentButton); } // Swap the toolbar panel and the copy // -- the order of operations is very important this.Controls.Add(tempPanel); toolbarButtonsPanel.Hide(); toolbarButtonsPanel.Controls.Clear(); toolbarButtonsPanel = tempPanel; // Reset toolbar panel with starting settings // since this is a new set of buttons SetToolbarButtonsPanelLocation(); toolbarButtonsIndex = 0; lastSlideDirection = SlideDirection.Next; CenterizeToolbar(); }