Esempio n. 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            GlassGradient activeGradient = normalGradient;

            if (UseStyles)
            {
                if (Enabled == false)
                {
                    activeGradient = GlassStyleManager.Active.ButtonDisabled;
                }
                else if (mouseDown)
                {
                    activeGradient = GlassStyleManager.Active.ButtonPressed;
                }
                else if (mouseOver)
                {
                    activeGradient = GlassStyleManager.Active.ButtonHover;
                }
                else if (highlight)
                {
                    activeGradient = GlassStyleManager.Active.ButtonHighlight;
                }
                else
                {
                    activeGradient = GlassStyleManager.Active.ButtonNormal;
                }
            }
            else
            {
                if (Enabled == false)
                {
                    activeGradient = disabledGradient;
                }
                else if (mouseDown)
                {
                    activeGradient = pressedGradient;
                }
                else if (mouseOver)
                {
                    activeGradient = hoverGradient;
                }
                else if (highlight)
                {
                    activeGradient = highlightGradient;
                }
                else
                {
                    activeGradient = normalGradient;
                }
            }

            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
            e.Graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            e.Graphics.SmoothingMode      = SmoothingMode.AntiAlias;

            Rectangle clientRectangle = ClientRectangle;

            clientRectangle.Inflate(-1, -1);

            bool activeIsGlass;

            GlassGradient sunk = new GlassGradient(Color.FromArgb(48, Color.White), Color.FromArgb(160, Color.Black));

            if (Parent is GlassPanel)
            {
                GlassPanel parent = (GlassPanel)Parent;
                if (parent.UseStyles)
                {
                    activeIsGlass = GlassStyleManager.Active.PanelIsGlass;
                }
                else
                {
                    activeIsGlass = parent.IsGlass;
                }
            }
            else
            {
                activeIsGlass = false;
            }

            GlassHelper.FillRoundedRectangle(clientRectangle, sunk, true, activeIsGlass, e.Graphics);

            Rectangle rectangle = clientRectangle;

            rectangle.Inflate(-depth, -depth);

            if (UseStyles)
            {
                activeIsGlass = GlassStyleManager.Active.ButtonIsGlass;
            }
            else
            {
                activeIsGlass = IsGlass;
            }

            GlassHelper.FillRoundedRectangle(rectangle, activeGradient, false, activeIsGlass, e.Graphics);

            e.Graphics.SetClip(ClientRectangle);

            GlassHelper.DrawRoundedBorder(rectangle, BorderColor, Depth / 4.0f, e.Graphics);

            StringAlignment vertical   = StringAlignment.Center;
            StringAlignment horizontal = StringAlignment.Center;

            if (Image != null)
            {
                switch (ImageAlign)
                {
                case ContentAlignment.BottomCenter:
                {
                    horizontal = StringAlignment.Center;
                    vertical   = StringAlignment.Far;
                    break;
                }

                case ContentAlignment.BottomLeft:
                {
                    horizontal = StringAlignment.Near;
                    vertical   = StringAlignment.Far;
                    break;
                }

                case ContentAlignment.BottomRight:
                {
                    horizontal = StringAlignment.Far;
                    vertical   = StringAlignment.Far;
                    break;
                }

                case ContentAlignment.MiddleCenter:
                {
                    horizontal = StringAlignment.Center;
                    vertical   = StringAlignment.Center;
                    break;
                }

                case ContentAlignment.MiddleLeft:
                {
                    horizontal = StringAlignment.Near;
                    vertical   = StringAlignment.Center;
                    break;
                }

                case ContentAlignment.MiddleRight:
                {
                    horizontal = StringAlignment.Far;
                    vertical   = StringAlignment.Center;
                    break;
                }

                case ContentAlignment.TopCenter:
                {
                    horizontal = StringAlignment.Center;
                    vertical   = StringAlignment.Near;
                    break;
                }

                case ContentAlignment.TopLeft:
                {
                    horizontal = StringAlignment.Near;
                    vertical   = StringAlignment.Near;
                    break;
                }

                case ContentAlignment.TopRight:
                {
                    horizontal = StringAlignment.Far;
                    vertical   = StringAlignment.Near;
                    break;
                }
                }

                int imageLeft = 0;
                int imageTop  = 0;

                switch (horizontal)
                {
                case StringAlignment.Near:
                    imageLeft = 4;
                    break;

                case StringAlignment.Center:
                    imageLeft = 1 + (ClientRectangle.Width / 2 - Image.Width / 2);
                    break;

                case StringAlignment.Far:
                    imageLeft = Width - Image.Width - 4;
                    break;
                }

                switch (vertical)
                {
                case StringAlignment.Near:
                    imageTop = 2;
                    break;

                case StringAlignment.Center:
                    imageTop = 0 + (ClientRectangle.Height / 2 - Image.Height / 2);
                    break;

                case StringAlignment.Far:
                    imageTop = Height - Image.Height - 2;
                    break;
                }

                if (Enabled == false)
                {
                    ControlPaint.DrawImageDisabled(e.Graphics, Image, imageLeft, imageTop,
                                                   GlassStyleManager.Active.ButtonDisabled.Bottom);
                }
                else
                {
                    if (mouseDown)
                    {
                        imageLeft++;
                        imageTop++;
                    }

                    e.Graphics.DrawImage(Image, imageLeft, imageTop, Image.Width, Image.Height);
                }
            }

            Rectangle textRectangle = ClientRectangle;
            int       textPadding   = Depth + (Depth / 4) + 2;

            textRectangle.Inflate(-textPadding, -textPadding);

            if (Image != null)
            {
                switch (horizontal)
                {
                case StringAlignment.Near:
                    textRectangle = new Rectangle(Image.Width + 4, 0, ClientRectangle.Width - Image.Width - 2,
                                                  ClientRectangle.Height);
                    break;

                case StringAlignment.Center:
                    textRectangle = new Rectangle(0, Image.Height + 2, ClientRectangle.Width,
                                                  ClientRectangle.Height - Image.Height - 2);
                    break;

                case StringAlignment.Far:
                    textRectangle = new Rectangle(0, 0, ClientRectangle.Width - Image.Width - 2,
                                                  ClientRectangle.Height);
                    break;
                }
            }

            if (Enabled == false)
            {
                GlassHelper.DrawText(Text, textRectangle, TextAlign, e.Graphics, true,
                                     ControlPaint.Dark(GlassStyleManager.Active.ForeColor), Color.Empty);
            }
            else
            {
                if (mouseDown)
                {
                    textRectangle.Offset(1, 1);
                }

                GlassHelper.DrawText(Text, textRectangle, TextAlign, e.Graphics, true, Color.Empty, Color.Empty);
            }
        }
Esempio n. 2
0
 protected override void OnPaint(PaintEventArgs e)
 {
     GlassHelper.DrawText(Text, ClientRectangle, TextAlign, e.Graphics, noWrap, Color.Empty, Color.Empty);
 }