private void UpdateWindowButtonPosition() { //if (DesignMode) return; if (!ControlBox) { return; } Dictionary <int, WindowButtons> priorityOrder = new Dictionary <int, WindowButtons>(3) { { 0, WindowButtons.Close }, { 1, WindowButtons.Maximize }, { 2, WindowButtons.Minimize } }; Point firstButtonLocation = new Point(ClientRectangle.Width - borderWidth - 25, borderWidth); int lastDrawedButtonPosition = firstButtonLocation.X - 25; MetroFormButton firstButton = null; if (windowButtonList.Count == 1) { foreach (KeyValuePair <WindowButtons, MetroFormButton> button in windowButtonList) { button.Value.Location = firstButtonLocation; } } else { foreach (KeyValuePair <int, WindowButtons> button in priorityOrder) { bool buttonExists = windowButtonList.ContainsKey(button.Value); if (firstButton == null && buttonExists) { firstButton = windowButtonList[button.Value]; firstButton.Location = firstButtonLocation; continue; } if (firstButton == null || !buttonExists) { continue; } windowButtonList[button.Value].Location = new Point(lastDrawedButtonPosition, borderWidth); lastDrawedButtonPosition = lastDrawedButtonPosition - 25; } } Refresh(); }
private void AddWindowButton(WindowButtons button) { if (windowButtonList == null) { windowButtonList = new Dictionary <WindowButtons, MetroFormButton>(); } if (windowButtonList.ContainsKey(button)) { return; } MetroFormButton newButton = new MetroFormButton(); if (button == WindowButtons.Close) { newButton.Text = "r"; } else if (button == WindowButtons.Minimize) { newButton.Text = "0"; } else if (button == WindowButtons.Maximize) { if (WindowState == FormWindowState.Normal) { newButton.Text = "1"; } else { newButton.Text = "2"; } } newButton.BackColor = Theme.WindowBackgroundColor; newButton.ForeColor = Theme.WindowForegroundColor; newButton.Tag = button; newButton.Size = new Size(25, 20); newButton.Anchor = AnchorStyles.Top | AnchorStyles.Right; newButton.TabStop = false; //remove the form controls from the tab stop newButton.Click += WindowButton_Click; Controls.Add(newButton); windowButtonList.Add(button, newButton); }