Beispiel #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (firstpaint)
            {
                System.ComponentModel.IContainer ic = this.GetParentContainerComponents();

                ic?.CopyToolTips(this, new Control[] { this, _cbsystem });

                firstpaint = false;
            }

            base.OnPaint(e);

            if (this.FlatStyle != FlatStyle.System)
            {
                int extraborder     = 1;
                int texthorzspacing = 1;

                textBoxBackArea = new Rectangle(ClientRectangle.X + extraborder, ClientRectangle.Y + extraborder,
                                                ClientRectangle.Width - 2 * extraborder, ClientRectangle.Height - 2 * extraborder);

                topBoxTextArea = new Rectangle(ClientRectangle.X + extraborder + texthorzspacing, ClientRectangle.Y + extraborder,
                                               ClientRectangle.Width - 2 * extraborder - 2 * texthorzspacing - ScrollBarWidth, ClientRectangle.Height - 2 * extraborder);

                arrowRectangleArea = new Rectangle(ClientRectangle.Width - ScrollBarWidth - extraborder, ClientRectangle.Y + extraborder,
                                                   ScrollBarWidth, ClientRectangle.Height - 2 * extraborder);

                topBoxOutline = new Rectangle(ClientRectangle.X, ClientRectangle.Y,
                                              ClientRectangle.Width - 1, ClientRectangle.Height - 1);


                int hoffset = arrowRectangleArea.Width / 3;
                int voffset = arrowRectangleArea.Height / 3;
                arrowpt1 = new Point(arrowRectangleArea.X + hoffset, arrowRectangleArea.Y + voffset);
                arrowpt2 = new Point(arrowRectangleArea.X + arrowRectangleArea.Width / 2, arrowRectangleArea.Y + arrowRectangleArea.Height - voffset);
                arrowpt3 = new Point(arrowRectangleArea.X + arrowRectangleArea.Width - hoffset, arrowpt1.Y);

                arrowpt1c = new Point(arrowpt1.X, arrowpt2.Y);
                arrowpt2c = new Point(arrowpt2.X, arrowpt1.Y);
                arrowpt3c = new Point(arrowpt3.X, arrowpt2.Y);

                Brush textb;
                Pen   p, p2;

                bool todraw = Enabled && Items.Count > 0;

                if (todraw)
                {
                    textb    = new SolidBrush(this.ForeColor);
                    p        = new Pen(BorderColor);
                    p2       = new Pen(ForeColor);
                    p2.Width = ArrowWidth;
                }
                else
                {
                    textb = new SolidBrush(ForeColor.Multiply(0.5F));
                    p     = new Pen(BorderColor.Multiply(0.5F));
                    p2    = null;
                }

                e.Graphics.DrawRectangle(p, topBoxOutline);

                Color bck;

                if (todraw)
                {
                    bck = (mouseover) ? MouseOverBackgroundColor : BackColor;
                }
                else
                {
                    bck = DisableBackgroundDisabledShadingGradient ? BackColor : BackColor.Multiply(0.5F);
                }

                Brush bbck;

                if (FlatStyle == FlatStyle.Popup && !DisableBackgroundDisabledShadingGradient)
                {
                    bbck = new System.Drawing.Drawing2D.LinearGradientBrush(textBoxBackArea, bck, bck.Multiply(ButtonColorScaling), 90);
                }
                else
                {
                    bbck = new SolidBrush(bck);
                }

                e.Graphics.FillRectangle(bbck, textBoxBackArea);

                //using (Brush test = new SolidBrush(Color.Red)) e.Graphics.FillRectangle(test, topBoxTextArea); // used to check alignment

                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                if (p2 != null)
                {
                    if (isActivated)
                    {
                        e.Graphics.DrawLine(p2, arrowpt1c, arrowpt2c);            // the arrow!
                        e.Graphics.DrawLine(p2, arrowpt2c, arrowpt3c);
                    }
                    else
                    {
                        e.Graphics.DrawLine(p2, arrowpt1, arrowpt2);            // the arrow!
                        e.Graphics.DrawLine(p2, arrowpt2, arrowpt3);
                    }
                }

                using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(RtlTranslateAlignment(TextAlign)))
                {
                    fmt.FormatFlags = StringFormatFlags.NoWrap;
                    e.Graphics.DrawString(this.Text, this.Font, textb, topBoxTextArea, fmt);
                }

                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;

                bbck.Dispose();

                textb.Dispose();
                p.Dispose();

                if (p2 != null)
                {
                    p2.Dispose();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Raises the <see cref="ButtonExt.Paint"/> event.
        /// </summary>
        /// <param name="pe">A <see cref="PaintEventArgs"/> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs pe)
        {
            if (FlatStyle != FlatStyle.Popup)      // popup style uses custom painting.
            {
                base.OnPaint(pe);
            }
            else
            {
                Rectangle border = ClientRectangle;
                border.Width--; border.Height--;

                Rectangle buttonarea = ClientRectangle;
                buttonarea.Inflate(-1, -1);                     // inside it.

                //System.Diagnostics.Debug.WriteLine("Paint " + this.Name + " " + ClientRectangle.ToString() + " MD " + mousedown + " MO " + mouseover);

                Color colBack   = Color.Empty;
                Color colBorder = Color.Empty;
                switch (_DrawState)
                {
                case DrawState.Disabled:
                    colBack   = BackColor.Multiply(0.5F);
                    colBorder = FlatAppearance.BorderColor.Multiply(_ButtonDisabledScaling);
                    break;

                case DrawState.Normal:
                default:
                    colBack   = BackColor;
                    colBorder = FlatAppearance.BorderColor;
                    break;

                case DrawState.Hover:
                    colBack   = FlatAppearance.MouseOverBackColor;
                    colBorder = FlatAppearance.BorderColor.Multiply(_BorderColorScaling);
                    break;

                case DrawState.Click:
                    colBack   = FlatAppearance.MouseDownBackColor;
                    colBorder = FlatAppearance.BorderColor.Multiply(_BorderColorScaling);
                    break;
                }

                using (var b = new LinearGradientBrush(buttonarea, colBack, colBack.Multiply(_ButtonColorScaling), 90))
                    pe.Graphics.FillRectangle(b, buttonarea);
                using (var p = new Pen(colBorder))
                    pe.Graphics.DrawRectangle(p, border);

                if (Image != null)
                {
                    if ((Enabled && DrawnImageAttributesEnabled != null) || (!Enabled && DrawnImageAttributesDisabled != null))
                    {
                        //System.Diagnostics.Debug.WriteLine("ButtonExt " + this.Name + " Draw image with IA");
                        pe.Graphics.DrawImage(Image, ControlHelpersStaticFunc.ImagePositionFromContentAlignment(ImageAlign, buttonarea, Image.Size),
                                              0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, (Enabled) ? DrawnImageAttributesEnabled : DrawnImageAttributesDisabled);
                    }
                    else
                    {
                        pe.Graphics.DrawImage(Image, ControlHelpersStaticFunc.ImagePositionFromContentAlignment(ImageAlign, buttonarea, Image.Size),
                                              0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel);
                    }
                }

                if (!string.IsNullOrEmpty(Text))
                {
                    using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(RtlTranslateAlignment(TextAlign)))
                        using (Brush textb = new SolidBrush((Enabled) ? this.ForeColor : this.ForeColor.Multiply(0.5F)))
                        {
                            if (this.UseMnemonic)
                            {
                                fmt.HotkeyPrefix = this.ShowKeyboardCues ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
                            }
                            if (this.AutoEllipsis)
                            {
                                fmt.Trimming = StringTrimming.EllipsisCharacter;
                            }
                            pe.Graphics.DrawString(this.Text, this.Font, textb, buttonarea, fmt);
                        }
                }

                if (Focused && ShowFocusCues)
                {
                    using (var p = new Pen(colBorder))
                    {
                        Rectangle rcFocus = border;

                        // Thicken the standard border by 1px.
                        rcFocus.Inflate(-1, -1);
                        pe.Graphics.DrawRectangle(p, rcFocus);

                        // Thicken that by an additional 1px, using something similar to ControlPaint.DrawFocusRectangle, but capable of honouring forecolour.
                        rcFocus.Inflate(-1, -1);
                        p.DashStyle   = DashStyle.Dash;
                        p.DashPattern = new[] { 1f, 1f };
                        pe.Graphics.DrawRectangle(p, rcFocus);
                    }
                }


                this.OnCustomPaint(pe);
            }
        }
Beispiel #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            var g    = e.Graphics;
            var rect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height);

            var textColor   = UseForeColor? ForeColor : Colors.LightText;
            var borderColor = Colors.GreySelection;
            var fillColor   = _useGenericBackColor ? (_isDefault ? Colors.DarkBlueBackground : Colors.LightBackground) : BackColor.Multiply(Colors.Brightness);
            var hoverColor  = _useGenericBackColor ? (_isDefault ? Colors.BlueBackground : Colors.LighterBackground) : ControlPaint.Light(BackColor.Multiply(Colors.Brightness));

            if (Enabled)
            {
                if (Checked)
                {
                    fillColor = Colors.HighlightFill;

                    switch (ButtonState)
                    {
                    case DarkControlState.Hover:
                        borderColor = Colors.GreyHighlight;
                        break;

                    case DarkControlState.Normal:
                        borderColor = Colors.HighlightBase;
                        break;
                    }
                }
                else
                {
                    switch (ButtonStyle)
                    {
                    case DarkButtonStyle.Normal:
                        if (Focused && TabStop)
                        {
                            borderColor = Colors.BlueHighlight;
                        }

                        switch (ButtonState)
                        {
                        case DarkControlState.Hover:
                            fillColor = hoverColor;
                            break;

                        case DarkControlState.Pressed:
                            fillColor = Colors.DarkBackground;
                            break;
                        }
                        break;

                    case DarkButtonStyle.Flat:
                        switch (ButtonState)
                        {
                        case DarkControlState.Normal:
                            fillColor = Colors.GreyBackground;
                            break;

                        case DarkControlState.Hover:
                            fillColor = Colors.MediumBackground;
                            break;

                        case DarkControlState.Pressed:
                            fillColor = Colors.DarkBackground;
                            break;
                        }
                        break;
                    }
                }
            }
            else
            {
                textColor = Colors.DisabledText;
                fillColor = Colors.DarkGreySelection;
            }

            using (var b = new SolidBrush(fillColor))
            {
                g.FillRectangle(b, rect);
            }

            if (ButtonStyle == DarkButtonStyle.Normal)
            {
                using (var p = new Pen(borderColor, 1))
                {
                    var modRect = new Rectangle(rect.Left, rect.Top, rect.Width - 1, rect.Height - 1);

                    g.DrawRectangle(p, modRect);
                }
            }

            var textOffsetX = 0;
            var textOffsetY = 0;

            if (Image != null)
            {
                var stringSize = g.MeasureString(Text, Font, rect.Size);

                var x = ClientSize.Width / 2 - Image.Size.Width / 2;
                var y = ClientSize.Height / 2 - Image.Size.Height / 2;

                switch (TextImageRelation)
                {
                case TextImageRelation.ImageAboveText:
                    textOffsetY = Image.Size.Height / 2 + ImagePadding / 2;
                    y           = y - ((int)(stringSize.Height / 2) + ImagePadding / 2);
                    break;

                case TextImageRelation.TextAboveImage:
                    textOffsetY = (Image.Size.Height / 2 + ImagePadding / 2) * -1;
                    y           = y + (int)(stringSize.Height / 2) + ImagePadding / 2;
                    break;

                case TextImageRelation.ImageBeforeText:
                    textOffsetX = Image.Size.Width + ImagePadding / 2;
                    x           = ImagePadding;
                    break;

                case TextImageRelation.TextBeforeImage:
                    x = x + (int)stringSize.Width;
                    break;
                }

                var imgRect = new Rectangle(x, y, Image.Width, Image.Height);
                g.DrawImage(Image, imgRect);

                // Dim brightness according to config
                using (var b = new SolidBrush(fillColor.MultiplyAlpha(1.0f - Colors.Brightness)))
                    g.FillRectangle(b, imgRect);
            }

            using (var b = new SolidBrush(textColor))
            {
                var modRect = new Rectangle(rect.Left + textOffsetX + Padding.Left,
                                            rect.Top + textOffsetY + Padding.Top, rect.Width - Padding.Horizontal,
                                            rect.Height - Padding.Vertical);

                if (Image != null)
                {
                    var stringFormat = new StringFormat
                    {
                        LineAlignment = StringAlignment.Center,
                        Alignment     = StringAlignment.Near,
                        Trimming      = StringTrimming.EllipsisCharacter
                    };

                    g.DrawString(Text, Font, b, modRect, stringFormat);
                }
                else
                {
                    var stringFormat = new StringFormat
                    {
                        LineAlignment = StringAlignment.Center,
                        Alignment     = StringAlignment.Center,
                        Trimming      = StringTrimming.EllipsisCharacter
                    };

                    g.DrawString(Text, Font, b, modRect, stringFormat);
                }
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            if (firstpaint)
            {
                System.ComponentModel.IContainer ic = this.GetParentContainerComponents();

                if (ic != null)    // yes we have a container object
                {
                    ic.CopyToolTips(this, new Control[] { this, _cbsystem });
                }

                firstpaint = true;
            }

            base.OnPaint(e);

            if (this.FlatStyle != FlatStyle.System)
            {
                int extraborder = 1;

                topBoxTextArea = new Rectangle(ClientRectangle.X + extraborder, ClientRectangle.Y + extraborder,
                                               ClientRectangle.Width - 2 * extraborder - ScrollBarWidth, ClientRectangle.Height - 2 * extraborder);

                arrowRectangleArea = new Rectangle(ClientRectangle.Width - ScrollBarWidth - extraborder, ClientRectangle.Y + extraborder,
                                                   ScrollBarWidth, ClientRectangle.Height - 2 * extraborder);

                topBoxOutline = new Rectangle(ClientRectangle.X, ClientRectangle.Y,
                                              ClientRectangle.Width - 1, ClientRectangle.Height - 1);

                topBoxTextTotalArea = new Rectangle(ClientRectangle.X + extraborder, ClientRectangle.Y + extraborder,
                                                    ClientRectangle.Width - 2 * extraborder, ClientRectangle.Height - 2 * extraborder);

                int hoffset = arrowRectangleArea.Width / 3;
                int voffset = arrowRectangleArea.Height / 3;
                arrowpt1 = new Point(arrowRectangleArea.X + hoffset, arrowRectangleArea.Y + voffset);
                arrowpt2 = new Point(arrowRectangleArea.X + arrowRectangleArea.Width / 2, arrowRectangleArea.Y + arrowRectangleArea.Height - voffset);
                arrowpt3 = new Point(arrowRectangleArea.X + arrowRectangleArea.Width - hoffset, arrowpt1.Y);

                arrowpt1c = new Point(arrowpt1.X, arrowpt2.Y);
                arrowpt2c = new Point(arrowpt2.X, arrowpt1.Y);
                arrowpt3c = new Point(arrowpt3.X, arrowpt2.Y);

                SizeF sz = e.Graphics.MeasureString("Represent THIS", this.Font);
                topBoxTextArea.Y += (topBoxTextArea.Height - (int)sz.Height) / 2;

                Brush textb;
                Pen   p, p2;

                bool todraw = Enabled && Items.Count > 0;

                if (todraw)
                {
                    textb    = new SolidBrush(this.ForeColor);
                    p        = new Pen(BorderColor);
                    p2       = new Pen(ForeColor);
                    p2.Width = ArrowWidth;
                }
                else
                {
                    textb = new SolidBrush(ForeColor.Multiply(0.5F));
                    p     = new Pen(BorderColor.Multiply(0.5F));
                    p2    = null;
                }

                e.Graphics.DrawRectangle(p, topBoxOutline);

                Color bck;

                if (todraw)
                {
                    bck = (mouseover) ? MouseOverBackgroundColor : BackColor;
                }
                else
                {
                    bck = BackColor.Multiply(0.5F);
                }

                Brush bbck;

                if (FlatStyle == FlatStyle.Popup)
                {
                    bbck = new System.Drawing.Drawing2D.LinearGradientBrush(topBoxTextTotalArea, bck, bck.Multiply(ButtonColorScaling), 90);
                }
                else
                {
                    bbck = new SolidBrush(bck);
                }

                e.Graphics.FillRectangle(bbck, topBoxTextTotalArea);

                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                if (p2 != null)
                {
                    if (isActivated)
                    {
                        e.Graphics.DrawLine(p2, arrowpt1c, arrowpt2c);            // the arrow!
                        e.Graphics.DrawLine(p2, arrowpt2c, arrowpt3c);
                    }
                    else
                    {
                        e.Graphics.DrawLine(p2, arrowpt1, arrowpt2);            // the arrow!
                        e.Graphics.DrawLine(p2, arrowpt2, arrowpt3);
                    }
                }

                using (StringFormat f = new StringFormat()
                {
                    Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near, FormatFlags = StringFormatFlags.NoWrap
                })
                    e.Graphics.DrawString(this.Text, this.Font, textb, topBoxTextArea, f);

                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;

                bbck.Dispose();

                textb.Dispose();
                p.Dispose();

                if (p2 != null)
                {
                    p2.Dispose();
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Raises the <see cref="ExtButton.Paint"/> event.
        /// </summary>
        /// <param name="pe">A <see cref="PaintEventArgs"/> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs pe)
        {
            if (FlatStyle != FlatStyle.Popup)      // popup style uses custom painting.
            {
                base.OnPaint(pe);
            }
            else
            {
                Rectangle border = ClientRectangle;
                border.Width--; border.Height--;

                Rectangle buttonarea = ClientRectangle;
                buttonarea.Inflate(-1, -1);                     // inside it.

                //System.Diagnostics.Debug.WriteLine("ButPaint " + this.Name + " " + ClientRectangle +" " + border + " " + buttonarea + " c " + BackColor + " " + FlatAppearance.BorderColor + " E:" + Enabled + " D:" + ButtonDisabledScaling);

                Color colBack   = Color.Empty;
                Color colBorder = Color.Empty;
                switch (drawState)
                {
                case DrawState.Disabled:
                    colBack   = BackColor.Multiply(buttonDisabledScaling);
                    colBorder = FlatAppearance.BorderColor.Multiply(buttonDisabledScaling);
                    break;

                case DrawState.Normal:
                default:
                    colBack   = BackColor;
                    colBorder = FlatAppearance.BorderColor;
                    break;

                case DrawState.Hover:
                    colBack   = FlatAppearance.MouseOverBackColor;
                    colBorder = FlatAppearance.BorderColor.Multiply(borderColorScaling);
                    break;

                case DrawState.Click:
                    colBack   = FlatAppearance.MouseDownBackColor;
                    colBorder = FlatAppearance.BorderColor.Multiply(borderColorScaling);
                    break;
                }

                if (buttonarea.Width >= 1 && buttonarea.Height >= 1)  // ensure size
                {
                    using (var b = new LinearGradientBrush(buttonarea, colBack, colBack.Multiply(buttonColorScaling), 90))
                        pe.Graphics.FillRectangle(b, buttonarea);       // linear grad brushes do not respect smoothing mode, btw
                }

                pe.Graphics.SmoothingMode = SmoothingMode.None;

                if (border.Width >= 1 && border.Height >= 1)        // ensure it does not except
                {
                    using (var p = new Pen(colBorder))
                        pe.Graphics.DrawRectangle(p, border);
                }

                if (buttonarea.Width < 1 || buttonarea.Height < 1)  // and no point drawing any more in the button area if its too small, it will except
                {
                    return;
                }

                if (Image != null)
                {
                    Size isize = (imagelayout == ImageLayout.Stretch) ? new Size(buttonarea.Height, buttonarea.Height) : Image.Size;

                    if ((Enabled && drawnImageAttributesEnabled != null) || (!Enabled && drawnImageAttributesDisabled != null))
                    {
                        //System.Diagnostics.Debug.WriteLine("ButtonExt " + this.Name + " Draw image with IA");
                        pe.Graphics.DrawImage(Image, ImageAlign.ImagePositionFromContentAlignment(buttonarea, isize),
                                              0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, (Enabled) ? drawnImageAttributesEnabled : drawnImageAttributesDisabled);
                    }
                    else
                    {
                        pe.Graphics.DrawImage(Image, ImageAlign.ImagePositionFromContentAlignment(buttonarea, isize),
                                              0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel);
                    }
                }

                pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

                if (!string.IsNullOrEmpty(Text))
                {
                    var txalign = Environment.OSVersion.Platform == PlatformID.Win32NT ? RtlTranslateAlignment(TextAlign) : TextAlign;      // MONO Bug cover over

                    using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(txalign))
                    {
                        using (Brush textb = new SolidBrush((Enabled) ? this.ForeColor : this.ForeColor.Multiply(ButtonDisabledScaling)))
                        {
                            if (this.UseMnemonic)
                            {
                                fmt.HotkeyPrefix = this.ShowKeyboardCues ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
                            }
                            if (this.AutoEllipsis)
                            {
                                fmt.Trimming = StringTrimming.EllipsisCharacter;
                            }
                            pe.Graphics.DrawString(this.Text, this.Font, textb, buttonarea, fmt);
                        }
                    }
                }

                pe.Graphics.SmoothingMode = SmoothingMode.None;

                if (Focused && ShowFocusCues)
                {
                    using (var p = new Pen(colBorder))
                    {
                        Rectangle rcFocus = border;

                        // Thicken the standard border by 1px.
                        rcFocus.Inflate(-1, -1);
                        pe.Graphics.DrawRectangle(p, rcFocus);

                        // Thicken that by an additional 1px, using something similar to ControlPaint.DrawFocusRectangle, but capable of honouring forecolour.
                        rcFocus.Inflate(-1, -1);
                        p.DashStyle   = DashStyle.Dash;
                        p.DashPattern = new[] { 1f, 1f };
                        pe.Graphics.DrawRectangle(p, rcFocus);
                    }
                }

                pe.Graphics.SmoothingMode = SmoothingMode.Default;

                this.OnCustomPaint(pe);
            }
        }
Beispiel #6
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            if (FlatStyle != FlatStyle.Popup)      // override popup style for us
            {
                base.OnPaint(pe);
            }
            else
            {
                Rectangle border = ClientRectangle;
                border.Width--; border.Height--;

                Rectangle focusrect = border;           // 1 inside it..
                focusrect.Inflate(-1, -1);

                Rectangle buttonarea = ClientRectangle;
                buttonarea.Inflate(-1, -1);                     // inside it.

                //System.Diagnostics.Debug.WriteLine("Paint " + this.Name + " " + ClientRectangle.ToString() + " MD " + mousedown + " MO " + mouseover);

                Color back;
                Brush b;
                Pen   p;

                if (!Enabled)
                {
                    back = BackColor.Multiply(0.5F);
                    b    = new System.Drawing.Drawing2D.LinearGradientBrush(buttonarea, back, back.Multiply(ButtonColorScaling), 90);
                    p    = new Pen(FlatAppearance.BorderColor.Multiply(ButtonDisabledScaling));
                }
                else
                {
                    back = (mousedown) ? FlatAppearance.MouseDownBackColor : ((mouseover) ? FlatAppearance.MouseOverBackColor : BackColor);
                    b    = new System.Drawing.Drawing2D.LinearGradientBrush(buttonarea, back, back.Multiply(ButtonColorScaling), 90);
                    p    = new Pen((mousedown || mouseover) ? FlatAppearance.BorderColor.Multiply(BorderColorScaling) : FlatAppearance.BorderColor);
                }


                pe.Graphics.DrawRectangle(p, border);
                pe.Graphics.FillRectangle(b, buttonarea);

                if (Focused)
                {
                    Pen p1 = new Pen(FlatAppearance.BorderColor);
                    pe.Graphics.DrawRectangle(p1, focusrect);
                    p1.Dispose();
                }

                System.Diagnostics.Debug.Assert(BackgroundImage == null);      // because i've used this and its incorrect

                if (Image != null)
                {
                    if (DrawnImageAttributesEnabled != null)
                    {
                        //System.Diagnostics.Debug.WriteLine("ButtonExt " + this.Name + " Draw image with IA");
                        pe.Graphics.DrawImage(Image, ControlHelpersStaticFunc.ImagePositionFromContentAlignment(ImageAlign, buttonarea, Image.Size),
                                              0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, (Enabled) ? DrawnImageAttributesEnabled : DrawnImageAttributesDisabled);
                    }
                    else
                    {
                        pe.Graphics.DrawImage(Image, ControlHelpersStaticFunc.ImagePositionFromContentAlignment(ImageAlign, buttonarea, Image.Size),
                                              0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel);
                    }
                }

                if (Text != null && Text.Length > 0)
                {
                    using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign))
                        using (Brush textb = new SolidBrush((Enabled) ? this.ForeColor : this.ForeColor.Multiply(0.5F)))
                            pe.Graphics.DrawString(this.Text, this.Font, textb, new RectangleF(buttonarea.Left, buttonarea.Top, buttonarea.Width, buttonarea.Height), fmt);
                }

                p.Dispose();
                b.Dispose();
            }
        }
        /// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.Paint"/>
        protected override void Paint(Graphics gr)
        {
            Rectangle area = ClientRectangle;

            if (ShowFocusBox)
            {
                if (Focused)
                {
                    using (var p = new Pen(MouseDownColor)
                    {
                        DashStyle = System.Drawing.Drawing2D.DashStyle.Dash
                    })
                    {
                        gr.DrawRectangle(p, new Rectangle(area.Left, area.Top, area.Width - 1, area.Height - 1));
                    }
                }
                area.Inflate(-1, -1);
            }

            int halfway = area.Height / 2;

            Rectangle drawupper  = new Rectangle(area.Left, area.Top, area.Width, halfway - 1);
            Rectangle drawlower  = new Rectangle(area.Left, area.Top + halfway, area.Width, halfway - 1);
            Rectangle sareaupper = drawupper;

            sareaupper.Height++;
            Rectangle sarealower = drawlower;

            sarealower.Height++;

            Color pcup, pcdown, pencolorup, pencolordown;

            pcup         = pcdown = Enabled ? BackColor : BackColor.Multiply(BackDisabledScaling);
            pencolordown = pencolorup = Enabled ? ForeColor : ForeColor.Multiply(ForeDisabledScaling);
            // System.Diagnostics.Debug.WriteLine("Colours " + pcup + " " + pencolordown);

            //System.Diagnostics.Debug.WriteLine("Ami running" + amitimer.Running);

            if (Enabled && (Hover || amitimer.Running))
            {
                bool  mbd  = MouseButtonsDown == GLMouseEventArgs.MouseButtons.Left || amitimer.Running;
                Color back = mbd ? MouseDownColor : MouseOverColor;
                Color fore = mbd ? ForeColor.Multiply(MouseSelectedColorScaling) : ForeColor;

                if (amitimer.Running ? (repeatdir == -1) : mouseoverbottom)           // if ami, we use savedir, else mouse pos
                {
                    pcdown       = back;
                    pencolordown = fore;
                }
                else
                {
                    pcup       = back;
                    pencolorup = fore;
                }
            }

            using (Brush b = new LinearGradientBrush(sareaupper, pcup, pcup.Multiply(FaceColorScaling), 90))
                gr.FillRectangle(b, drawupper);

            using (Brush b = new LinearGradientBrush(sarealower, pcdown, pcdown.Multiply(FaceColorScaling), 270))
                gr.FillRectangle(b, drawlower);

            using (Pen p = new Pen(pencolorup))
            {
                int hoffset = drawupper.Width / 3;
                int voffset = drawupper.Height / 3;

                Point arrowpt1u = new Point(drawupper.X + hoffset, drawupper.Y + drawupper.Height - voffset);
                Point arrowpt2u = new Point(drawupper.X + drawupper.Width / 2, drawupper.Y + voffset);
                Point arrowpt3u = new Point(drawupper.X + drawupper.Width - hoffset, arrowpt1u.Y);
                gr.DrawLine(p, arrowpt1u, arrowpt2u);            // the arrow!
                gr.DrawLine(p, arrowpt2u, arrowpt3u);
            }

            using (Pen p = new Pen(pencolordown))
            {
                int hoffset = drawlower.Width / 3;
                int voffset = drawlower.Height / 3;

                Point arrowpt1d = new Point(drawlower.X + hoffset, drawlower.Y + voffset);
                Point arrowpt2d = new Point(drawlower.X + drawlower.Width / 2, drawlower.Y + drawlower.Height - voffset);
                Point arrowpt3d = new Point(drawlower.X + drawlower.Width - hoffset, arrowpt1d.Y);

                gr.DrawLine(p, arrowpt1d, arrowpt2d);            // the arrow!
                gr.DrawLine(p, arrowpt2d, arrowpt3d);
            }
        }
Beispiel #8
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            if (FlatStyle != FlatStyle.Popup)      // override popup style for us
            {
                base.OnPaint(pe);
            }
            else
            {
                Rectangle border = ClientRectangle;
                border.Width--; border.Height--;

                Rectangle focusrect = border;           // 1 inside it..
                focusrect.Inflate(-1, -1);

                Rectangle buttonarea = ClientRectangle;
                buttonarea.Inflate(-1, -1);                     // inside it.

                //Console.WriteLine("Paint " + this.Name + " " + ClientRectangle.ToString());

                Color back;
                Brush b;
                Pen   p;

                if (!Enabled)
                {
                    back = BackColor.Multiply(0.5F);
                    b    = new System.Drawing.Drawing2D.LinearGradientBrush(buttonarea, back, back.Multiply(ButtonColorScaling), 90);
                    p    = new Pen(FlatAppearance.BorderColor.Multiply(ButtonDisabledScaling));
                }
                else
                {
                    back = (mousedown) ? FlatAppearance.MouseDownBackColor : ((mouseover) ? FlatAppearance.MouseOverBackColor : BackColor);
                    b    = new System.Drawing.Drawing2D.LinearGradientBrush(buttonarea, back, back.Multiply(ButtonColorScaling), 90);
                    p    = new Pen((mousedown || mouseover) ? FlatAppearance.BorderColor.Multiply(BorderColorScaling) : FlatAppearance.BorderColor);
                }

                pe.Graphics.DrawRectangle(p, border);
                pe.Graphics.FillRectangle(b, buttonarea);

                if (Focused)
                {
                    Pen p1 = new Pen(FlatAppearance.BorderColor);
                    pe.Graphics.DrawRectangle(p1, focusrect);
                    p1.Dispose();
                }

                System.Diagnostics.Debug.Assert(BackgroundImage == null);      // because i've used this and its incorrect

                if (Image != null)
                {
                    pe.Graphics.DrawImage(Image, new Rectangle(ClientRectangle.Width / 2 - Image.Width / 2, ClientRectangle.Height / 2 - Image.Height / 2, Image.Width, Image.Height),
                                          0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel);
                }
                else
                {
                    SizeF sz = pe.Graphics.MeasureString(this.Text, this.Font);

                    Brush textb = new SolidBrush((Enabled) ? this.ForeColor : this.ForeColor.Multiply(0.5F));

                    pe.Graphics.DrawString(this.Text, this.Font, textb,
                                           buttonarea.Left + (buttonarea.Width - sz.Width) / 2,
                                           buttonarea.Top + (buttonarea.Height - sz.Height) / 2);

                    textb.Dispose();
                }

                p.Dispose();
                b.Dispose();
            }
        }