예제 #1
0
        private void WindowButton_Click(object sender, EventArgs e)
        {
            MetroFormButton btn = sender as MetroFormButton;

            if (btn != null)
            {
                WindowButtons btnFlag = (WindowButtons)btn.Tag;
                if (btnFlag == WindowButtons.Close)
                {
                    Close();
                }
                else if (btnFlag == WindowButtons.Minimize)
                {
                    WindowState = FormWindowState.Minimized;
                }
                else if (btnFlag == WindowButtons.Maximize)
                {
                    if (WindowState == FormWindowState.Normal)
                    {
                        WindowState = FormWindowState.Maximized;
                        btn.Text    = "2";
                    }
                    else
                    {
                        WindowState = FormWindowState.Normal;
                        btn.Text    = "1";
                    }
                }
                else if (btnFlag == WindowButtons.Help)
                {
                    OnHelpButtonClicked(new CancelEventArgs(false));
                    btn.Text = "s";
                }
            }
        }
예제 #2
0
        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.Tag  = button;
            newButton.Size = new Size(25, 20);

            //Moneim
            switch (RightToLeft)
            {
            case RightToLeft.No:
                newButton.Anchor = AnchorStyles.Top | AnchorStyles.Right;
                break;

            case RightToLeft.Yes:
                newButton.Anchor = AnchorStyles.Top | AnchorStyles.Left;
                break;
            }

            newButton.Click += new EventHandler(WindowButton_Click);
            Controls.Add(newButton);

            windowButtonList.Add(button, newButton);
        }
예제 #3
0
        private void UpdateWindowButtonPosition()
        {
            // Button drawing priority.
            var priorityOrder = new Dictionary <int, WindowButtons>(4)
            {
                { 0, WindowButtons.Close },
                { 1, WindowButtons.Maximize },
                { 2, WindowButtons.Minimize },
                { 3, WindowButtons.Help }
            };

            // Position of the first button drawn
            var firstButtonLocation = new Point(Width - FirstButtonSpacerWidth, 8);

            // Number of buttons drawn in total
            var lastDrawedButtonPosition = firstButtonLocation.X - 20;

            // Object representation of the first button drawn
            MetroFormButton firstButton = null;

            // Only one button to draw.
            if (windowButtonList.Count == 1)
            {
                foreach (var button in windowButtonList)
                {
                    button.Value.Location = firstButtonLocation;
                    break;
                }
                return;
            }

            // Draw buttons in priority order
            foreach (var button in priorityOrder)
            {
                var 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, 8);
                lastDrawedButtonPosition = lastDrawedButtonPosition - 20;
            }

            Refresh();
        }
예제 #4
0
        private void UpdateWindowButtonPosition()
        {
            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();
        }
예제 #5
0
        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";
                }
            }
            else if (button == WindowButtons.Help)
            {
                newButton.Text = "s";
            }

            newButton.Tag    = button;
            newButton.Size   = new Size(30, 20);
            newButton.Anchor = AnchorStyles.Top | AnchorStyles.Right;
            newButton.Click += new EventHandler(WindowButton_Click);
            Controls.Add(newButton);

            windowButtonList.Add(button, newButton);
        }
예제 #6
0
        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.Style   = Style;
            newButton.Theme   = Theme;
            newButton.Tag     = button;
            newButton.Size    = new Size(25, 22);
            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);
        }
예제 #7
0
        public void AddNewWindowButton(WindowButtons button) // Method for adding WindowButtons (ex: Close window, minimize window, etc.) This method was copied from the MetroFramework source, but I needed the window buttons to go on the header panel instead.
        {
            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.Style   = Style;
            newButton.Theme   = MetroThemeStyle.Dark; // Changed from default
            newButton.Tag     = button;
            newButton.Size    = new Size(25, 20);
            newButton.Anchor  = AnchorStyles.None; // Changed from default, I set all anchors to none for now, just so I didn't have to worry about those messing with the display
            newButton.TabStop = false;
            newButton.Click  += WindowButton_Click;
            Header.Controls.Add(newButton); // Changed to add the buttons on the header layer, instead of form1, as the header panel would cover the window buttons
            windowButtonList.Add(button, newButton);
        }
예제 #8
0
        private void AddWindowButton(WindowButtons button)
        {
            if (_windowButtons[(int)button] != null)
            {
                throw new InvalidOperationException();
            }

            MetroFormButton newButton = new MetroFormButton
            {
                Text   = GetButtonText(button),
                Tag    = button,
                Size   = new Size(25, 20),
                Anchor = AnchorStyles.Top | AnchorStyles.Right
            };

            newButton.Click += WindowButton_Click;
            Controls.Add(newButton);
            _windowButtons[(int)button] = newButton;
        }
예제 #9
0
        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.Style = Style;
            newButton.Theme = Theme;
            newButton.Tag = button;
            newButton.Size = new Size(25, 20);
            newButton.Anchor = AnchorStyles.Top | AnchorStyles.Right;
            newButton.Click += WindowButton_Click;
            Controls.Add(newButton);

            windowButtonList.Add(button, newButton);
        }
예제 #10
0
        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 = MetroColors.Brown;
            newButton.UseCustomBackColor = true;
            newButton.Style = Style;
            newButton.Theme = Theme;
            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);
        }
예제 #11
0
        /// <summary>
        /// Adds the window button.
        /// </summary>
        /// <param name="button">The button.</param>
        private void AddWindowButton(WindowButtons button)
        {
            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";
            }
            else if (button == WindowButtons.Pin)
            {
                newButton.Text = TopMost ? "=" : "ë";
            }

            newButton.Style = Style;
            newButton.Theme = Theme;
            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);
        }
예제 #12
0
        private void AddWindowButton(WindowButtons button)
        {
            if (_windowButtons[(int)button] != null ) throw new InvalidOperationException();

            MetroFormButton newButton = new MetroFormButton
                {
                    Text = GetButtonText(button),
                    Tag = button,
                    Size = new Size(25, 20),
                    Anchor = AnchorStyles.Top | AnchorStyles.Right
                };

            newButton.Click += WindowButton_Click;
            Controls.Add(newButton);
            _windowButtons[(int)button] = newButton;
        }