private void AddControlBox(FormControlBox controlBox) { if (this._controlBoxDictionary == null) { this._controlBoxDictionary = new Dictionary <FormControlBox, ModernControlBox>(); } if (this._controlBoxDictionary.ContainsKey(controlBox)) { return; } ModernControlBox modernControlBox = new ModernControlBox(); if (controlBox == FormControlBox.Close) { modernControlBox.Text = "r"; } else if (controlBox == FormControlBox.Minimize) { modernControlBox.Text = "0"; } else if (controlBox == FormControlBox.Maximize) { if (this.WindowState == FormWindowState.Normal) { modernControlBox.Text = "1"; } else { modernControlBox.Text = "2"; } } modernControlBox.ColorStyle = this.ColorStyle; modernControlBox.ThemeStyle = this.ThemeStyle; modernControlBox.Tag = controlBox; modernControlBox.Size = new Size(25, 20); modernControlBox.Anchor = AnchorStyles.Top | AnchorStyles.Right; modernControlBox.TabStop = false; modernControlBox.Click += this.OnControlBoxClick; modernControlBox.UseCustomBackColor = this.ControlBoxUseCustomBackColor; modernControlBox.UseCustomForeColor = this.ControlBoxUseCustomForeColor; if (this.ControlBoxUseCustomBackColor) { modernControlBox.BackColor = this.ControlBoxCustomBackColor; } if (this.ControlBoxUseCustomForeColor) { modernControlBox.ForeColor = this.ControlBoxCustomForeColor; } this.Controls.Add(modernControlBox); this._controlBoxDictionary.Add(controlBox, modernControlBox); }
/// <summary> /// Updates the control box position. /// </summary> private void UpdateControlBoxPosition() { if (!this.UseControlBox) { return; } Dictionary <int, FormControlBox> priorityOrder = new Dictionary <int, FormControlBox>(); if (this.UseCloseBox) { priorityOrder.Add(0, FormControlBox.Close); } if (this.UseMaximizeBox) { priorityOrder.Add(1, FormControlBox.Maximize); } if (this.UseMinimizeBox) { priorityOrder.Add(2, FormControlBox.Minimize); } Point firstControlBoxLocation; if (this.ShowBorder) { firstControlBoxLocation = new Point(this.ClientRectangle.Width - 25 - 1, 1 + this.TopBarHeight); } else { firstControlBoxLocation = new Point(this.ClientRectangle.Width - 25, 0 + this.TopBarHeight); } int lastDrawedControlBoxPosition = firstControlBoxLocation.X - 25; ModernControlBox firstControlBox = null; if (this._controlBoxDictionary.Count == 1) { foreach (KeyValuePair <FormControlBox, ModernControlBox> item in this._controlBoxDictionary) { item.Value.Location = firstControlBoxLocation; } } else { foreach (KeyValuePair <int, FormControlBox> item in priorityOrder) { bool exists = this._controlBoxDictionary.ContainsKey(item.Value); if (firstControlBox == null && exists) { firstControlBox = this._controlBoxDictionary[item.Value]; firstControlBox.Location = firstControlBoxLocation; continue; } if (firstControlBox == null || !exists) { continue; } this._controlBoxDictionary[item.Value].Location = new Point(lastDrawedControlBoxPosition, this.TopBarHeight + (this.ShowBorder ? 1 : 0)); lastDrawedControlBoxPosition = lastDrawedControlBoxPosition - 25; } } this.Refresh(); }