Ejemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (!showSplit)
            {
                return;
            }

            Graphics  g      = pevent.Graphics;
            Rectangle bounds = ClientRectangle;

            // calculate the current dropdown rectangle.
            dropDownRectangle = new Rectangle(bounds.Right - PushButtonWidth - 1, BorderSize, PushButtonWidth, bounds.Height - BorderSize * 2);

            int       internalBorder = BorderSize;
            Rectangle focusRect      =
                new Rectangle(internalBorder,
                              internalBorder,
                              bounds.Width - dropDownRectangle.Width - internalBorder,
                              bounds.Height - (internalBorder * 2));

            Pen shadow = SystemPens.ButtonShadow;
            Pen face   = SystemPens.ButtonFace;


            shadow = new Pen(MetroPaint.BorderColor.Button.Disabled(Theme));
            face   = new Pen(MetroPaint.BorderColor.Button.Normal(Theme));

            // if (palette != null)
            // {
            //     shadow = new Pen(palette.ColorTable.GripDark);
            //     face = new Pen(palette.ColorTable.GripLight);
            // }

            if (RightToLeft == RightToLeft.Yes)
            {
                dropDownRectangle.X = bounds.Left + 1;
                focusRect.X         = dropDownRectangle.Right;

                // TODO: Fix Lines here?
                // draw two lines at the edge of the dropdown button
                g.DrawLine(shadow, bounds.Left + PushButtonWidth, BorderSize, bounds.Left + PushButtonWidth, bounds.Bottom - BorderSize);
                g.DrawLine(face, bounds.Left + PushButtonWidth + 1, BorderSize, bounds.Left + PushButtonWidth + 1, bounds.Bottom - BorderSize);
            }
            else
            {
                // draw two lines at the edge of the dropdown button
                g.DrawLine(shadow, bounds.Right - PushButtonWidth, BorderSize, bounds.Right - PushButtonWidth, bounds.Bottom - BorderSize);
                g.DrawLine(face, bounds.Right - PushButtonWidth - 1, BorderSize, bounds.Right - PushButtonWidth - 1, bounds.Bottom - BorderSize);
            }

            // Draw an arrow in the correct location
            MetroDrawingMethods.PaintDownArrow(g, dropDownRectangle, MetroPaint.BorderColor.Button.Disabled(Theme), 0, 0);
        }
Ejemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            //Set Colors
            Color nudTextColor = !useStyleColors?MetroPaint.ForeColor.NumericUpDown.Normal(Theme) : MetroPaint.GetStyleColor(Style);

            if (!this.Enabled)
            {
                nudTextColor = MetroPaint.ForeColor.NumericUpDown.Disabled(Theme);
            }

            Color nudTextBackColor = !useAlternateColors?MetroPaint.BackColor.NumericUpDown.Normal(Theme) : MetroPaint.BackColor.NumericUpDown.Alternate(Theme);

            Color nudControlsBorderColor = MetroPaint.BorderColor.NumericUpDown.Normal(Theme);
            Color nudControlsBackColor   = MetroPaint.BackColor.NumericUpDown.Normal(Theme);
            Color nudControlsForeColor   = MetroPaint.BorderColor.NumericUpDown.Normal(Theme);

            bool Debug = false; //for check consistency of the Rectangles

            var       gr      = e.Graphics;
            Rectangle nudRect = this.ClientRectangle;

            nudRect.Height -= 1;
            nudRect.Width  -= 1;


            gr.FillRectangle(new SolidBrush(nudControlsBackColor), nudRect);
            gr.DrawRectangle(new Pen(nudControlsBorderColor), nudRect);

            if (Debug)
            {
                gr.DrawRectangle(new Pen(Color.Red), nudRect);
            }

            foreach (Control c in this.Controls)
            {
                if (!(c is TextBox)) // -->Up Down Buttons
                {
                    //override inner's control paintevent (Button UP & Down)
                    typeof(Control).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, c, new object[] { true });
                    c.Paint += (sender, pev) =>
                    {
                        var g = pev.Graphics;
                        int h = c.Height;
                        int w = c.Width;

                        Rectangle buttonsUpDownRect = c.ClientRectangle;
                        buttonsUpDownRect.Height -= 1;
                        buttonsUpDownRect.Width  -= 1;

                        //control rectnagles
                        Rectangle UpArrowRect   = new Rectangle(1, 1, w - 3, h / 2 - 2);
                        Rectangle DownArrowRect = new Rectangle(1, h / 2, w - 3, h / 2 - 2);

                        //Draw Controls Rectangle
                        g.DrawRectangle(new Pen(nudControlsBackColor), buttonsUpDownRect);
                        if (Debug)
                        {
                            g.DrawRectangle(new Pen(Color.Green), buttonsUpDownRect);
                        }

                        //Cutom Draw Buttons
                        if (customDrawButtons)
                        {
                            //ClearBackGround
                            g.FillRectangle(new SolidBrush(nudControlsBackColor), buttonsUpDownRect);

                            //draw BackGround
                            g.FillRectangle(new SolidBrush(nudControlsBackColor), UpArrowRect);
                            g.FillRectangle(new SolidBrush(nudControlsBackColor), DownArrowRect);
                            g.DrawRectangle(new Pen(nudControlsBorderColor), UpArrowRect);
                            g.DrawRectangle(new Pen(nudControlsBorderColor), DownArrowRect);
                            if (Debug)
                            {
                                g.DrawRectangle(new Pen(Color.Violet), UpArrowRect);
                            }
                            if (Debug)
                            {
                                g.DrawRectangle(new Pen(Color.Blue), DownArrowRect);
                            }

                            //draw Arrows
                            MetroDrawingMethods.PaintUpArrow(g, UpArrowRect, nudControlsForeColor, 0, -1);
                            MetroDrawingMethods.PaintDownArrow(g, DownArrowRect, nudControlsForeColor, 0, 0);
                        }
                    };
                }
                else if ((c is TextBox))
                {
                    //Set Textbox fore Color
                    c.ForeColor = nudTextColor;
                    if (Debug)
                    {
                        c.ForeColor = Color.Red;
                    }

                    //Set Textbox back Color
                    c.BackColor = nudTextBackColor;
                    if (Debug)
                    {
                        c.BackColor = Color.Yellow;
                    }

                    c.Font = MetroFonts.Label(metroLabelSize, metroLabelWeight);
                }
            }
        }