Ejemplo n.º 1
0
        /// <include file='doc\Label.uex' path='docs/doc[@for="Label.OnPaint"]/*' />
        /// <devdoc>
        /// </devdoc>
        /// <internalonly/>
        protected override void OnPaint(PaintEventArgs e)
        {
            Animate();

            ImageAnimator.UpdateFrames();
            Image i = this.Image;

            if (i != null)
            {
                DrawImage(e.Graphics, i, ClientRectangle, RtlTranslateAlignment(ImageAlign));
            }

            Color color = e.Graphics.GetNearestColor((Enabled) ? ForeColor : DisabledColor);

            // Do actual drawing
            StringFormat stringFormat = CreateStringFormat();

            if (Enabled)
            {
                using (Brush brush = new SolidBrush(color)) {
                    e.Graphics.DrawString(Text, Font, brush, this.ClientRectangle, stringFormat);
                }
            }
            else
            {
                ControlPaint.DrawStringDisabled(e.Graphics, Text, Font, color,
                                                this.ClientRectangle,
                                                stringFormat);
            }
            stringFormat.Dispose();

            base.OnPaint(e); // raise paint event
        }
Ejemplo n.º 2
0
        private void Draw(Graphics g)
        {
            // Fill the background if we aren't transparent.
            if (!renderTransparent)
            {
                using (Brush brush = CreateBackgroundBrush())
                {
                    g.FillRectangle(brush, ClientRectangle);
                }
            }

            // Draw the image
            if (image != null)
            {
                this.DrawImage(g, image, base.ClientRectangle, this.imageAlign);
            }

            // Draw the text within the label.
            RectangleF   layout = (RectangleF)ClientRectangle;
            StringFormat format = GetStringFormat();

            if (text != null && text != String.Empty)
            {
                layout.X += 1;
                if (Enabled)
                {
                    Brush brush = new SolidBrush(ForeColor);
                    g.DrawString(Text, Font, brush, layout, format);
                    brush.Dispose();
                }
                else
                {
                    ControlPaint.DrawStringDisabled
                        (g, Text, Font, BackColor, layout, format);
                }
            }
        }
        private void DrawGroupBox(PaintEventArgs e)
        {
            Graphics  graphics        = e.Graphics;
            Rectangle clientRectangle = base.ClientRectangle;
            int       num             = 8;
            Color     disabledColor   = base.DisabledColor;
            Pen       pen             = new Pen(ControlPaint.Light(disabledColor, 1f));
            Pen       pen2            = new Pen(ControlPaint.Dark(disabledColor, 0f));

            clientRectangle.X     += num;
            clientRectangle.Width -= 2 * num;
            try
            {
                Size size;
                int  num2;
                if (this.UseCompatibleTextRendering)
                {
                    using (Brush brush = new SolidBrush(this.ForeColor))
                    {
                        using (StringFormat format = new StringFormat())
                        {
                            format.HotkeyPrefix = this.ShowKeyboardCues ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
                            if (this.RightToLeft == RightToLeft.Yes)
                            {
                                format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                            }
                            size = Size.Ceiling(graphics.MeasureString(this.Text, this.Font, clientRectangle.Width, format));
                            if (base.Enabled)
                            {
                                graphics.DrawString(this.Text, this.Font, brush, clientRectangle, format);
                            }
                            else
                            {
                                ControlPaint.DrawStringDisabled(graphics, this.Text, this.Font, disabledColor, clientRectangle, format);
                            }
                        }
                        goto Label_01E7;
                    }
                }
                using (WindowsGraphics graphics2 = WindowsGraphics.FromGraphics(graphics))
                {
                    IntTextFormatFlags flags = IntTextFormatFlags.TextBoxControl | IntTextFormatFlags.WordBreak;
                    if (!this.ShowKeyboardCues)
                    {
                        flags |= IntTextFormatFlags.HidePrefix;
                    }
                    if (this.RightToLeft == RightToLeft.Yes)
                    {
                        flags |= IntTextFormatFlags.RightToLeft;
                        flags |= IntTextFormatFlags.Right;
                    }
                    using (WindowsFont font = WindowsGraphicsCacheManager.GetWindowsFont(this.Font))
                    {
                        size = graphics2.MeasureText(this.Text, font, new Size(clientRectangle.Width, 0x7fffffff), flags);
                        if (base.Enabled)
                        {
                            graphics2.DrawText(this.Text, font, clientRectangle, this.ForeColor, flags);
                        }
                        else
                        {
                            ControlPaint.DrawStringDisabled(graphics2, this.Text, this.Font, disabledColor, clientRectangle, (TextFormatFlags)flags);
                        }
                    }
                }
Label_01E7:
                num2 = num;
                if (this.RightToLeft == RightToLeft.Yes)
                {
                    num2 += clientRectangle.Width - size.Width;
                }
                int num3 = Math.Min((int)(num2 + size.Width), (int)(base.Width - 6));
                int num4 = base.FontHeight / 2;
                graphics.DrawLine(pen, 1, num4, 1, base.Height - 1);
                graphics.DrawLine(pen2, 0, num4, 0, base.Height - 2);
                graphics.DrawLine(pen, 0, base.Height - 1, base.Width, base.Height - 1);
                graphics.DrawLine(pen2, 0, base.Height - 2, base.Width - 1, base.Height - 2);
                graphics.DrawLine(pen2, 0, num4 - 1, num2, num4 - 1);
                graphics.DrawLine(pen, 1, num4, num2, num4);
                graphics.DrawLine(pen2, num3, num4 - 1, base.Width - 2, num4 - 1);
                graphics.DrawLine(pen, num3, num4, base.Width - 1, num4);
                graphics.DrawLine(pen, (int)(base.Width - 1), (int)(num4 - 1), (int)(base.Width - 1), (int)(base.Height - 1));
                graphics.DrawLine(pen2, base.Width - 2, num4, base.Width - 2, base.Height - 2);
            }
            finally
            {
                pen.Dispose();
                pen2.Dispose();
            }
        }
Ejemplo n.º 4
0
        private void DrawGroupBox(PaintEventArgs e)
        {
            Graphics  graphics      = e.Graphics;
            Rectangle textRectangle = ClientRectangle; // Max text bounding box passed to drawing methods to support RTL.

            int textOffset = 8;                        // Offset from the left bound.

            Color backColor = DisabledColor;

            Pen  light = new Pen(ControlPaint.Light(backColor, 1.0f));
            Pen  dark  = new Pen(ControlPaint.Dark(backColor, 0f));
            Size textSize;

            textRectangle.X     += textOffset;
            textRectangle.Width -= 2 * textOffset;

            try {
                if (UseCompatibleTextRendering)
                {
                    using (Brush textBrush = new SolidBrush(ForeColor)){
                        using (StringFormat format = new StringFormat()){
                            format.HotkeyPrefix = ShowKeyboardCues ? System.Drawing.Text.HotkeyPrefix.Show : System.Drawing.Text.HotkeyPrefix.Hide;

                            // Adjust string format for Rtl controls

                            if (RightToLeft == RightToLeft.Yes)
                            {
                                format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                            }

                            textSize = Size.Ceiling(graphics.MeasureString(Text, Font, textRectangle.Width, format));

                            if (Enabled)
                            {
                                graphics.DrawString(Text, Font, textBrush, textRectangle, format);
                            }
                            else
                            {
                                ControlPaint.DrawStringDisabled(graphics, Text, Font, backColor, textRectangle, format);
                            }
                        }
                    }
                }
                else
                {
                    using (WindowsGraphics wg = WindowsGraphics.FromGraphics(graphics)){
                        IntTextFormatFlags flags = IntTextFormatFlags.WordBreak | IntTextFormatFlags.TextBoxControl;

                        if (!ShowKeyboardCues)
                        {
                            flags |= IntTextFormatFlags.HidePrefix;
                        }

                        if (RightToLeft == RightToLeft.Yes)
                        {
                            flags |= IntTextFormatFlags.RightToLeft;
                            flags |= IntTextFormatFlags.Right;
                        }


                        using (WindowsFont wfont = WindowsGraphicsCacheManager.GetWindowsFont(this.Font)) {
                            textSize = wg.MeasureText(Text, wfont, new Size(textRectangle.Width, int.MaxValue), flags);

                            if (Enabled)
                            {
                                wg.DrawText(Text, wfont, textRectangle, ForeColor, flags);
                            }
                            else
                            {
                                ControlPaint.DrawStringDisabled(wg, Text, Font, backColor, textRectangle, ((TextFormatFlags)flags));
                            }
                        }
                    }
                }

                int textLeft = textOffset;    // Left side of binding box (independent on RTL).

                if (RightToLeft == RightToLeft.Yes)
                {
                    textLeft += textRectangle.Width - textSize.Width;
                }

                // Math.Min to assure we paint at least a small line.
                int textRight = Math.Min(textLeft + textSize.Width, Width - 6);

                int boxTop = FontHeight / 2;

                if (SystemInformation.HighContrast && AccessibilityImprovements.Level1)
                {
                    Color boxColor;
                    if (Enabled)
                    {
                        boxColor = ForeColor;
                    }
                    else
                    {
                        boxColor = SystemColors.GrayText;
                    }
                    bool needToDispose = !boxColor.IsSystemColor;
                    Pen  boxPen        = null;
                    try {
                        if (needToDispose)
                        {
                            boxPen = new Pen(boxColor);
                        }
                        else
                        {
                            boxPen = SystemPens.FromSystemColor(boxColor);
                        }

                        // left
                        graphics.DrawLine(boxPen, 0, boxTop, 0, Height);
                        //bottom
                        graphics.DrawLine(boxPen, 0, Height - 1, Width, Height - 1);
                        //top-left
                        graphics.DrawLine(boxPen, 0, boxTop, textLeft, boxTop);
                        //top-right
                        graphics.DrawLine(boxPen, textRight, boxTop, Width - 1, boxTop);
                        //right
                        graphics.DrawLine(boxPen, Width - 1, boxTop, Width - 1, Height - 1);
                    }
                    finally {
                        if (needToDispose && boxPen != null)
                        {
                            boxPen.Dispose();
                        }
                    }
                }
                else
                {
                    // left
                    graphics.DrawLine(light, 1, boxTop, 1, Height - 1);
                    graphics.DrawLine(dark, 0, boxTop, 0, Height - 2);

                    // bottom
                    graphics.DrawLine(light, 0, Height - 1, Width, Height - 1);
                    graphics.DrawLine(dark, 0, Height - 2, Width - 1, Height - 2);

                    // top-left

                    graphics.DrawLine(dark, 0, boxTop - 1, textLeft, boxTop - 1);
                    graphics.DrawLine(light, 1, boxTop, textLeft, boxTop);

                    // top-right
                    graphics.DrawLine(dark, textRight, boxTop - 1, Width - 2, boxTop - 1);
                    graphics.DrawLine(light, textRight, boxTop, Width - 1, boxTop);

                    // right
                    graphics.DrawLine(light, Width - 1, boxTop - 1, Width - 1, Height - 1);
                    graphics.DrawLine(dark, Width - 2, boxTop, Width - 2, Height - 2);
                }
            }
            finally {
                light.Dispose();
                dark.Dispose();
            }
        }
Ejemplo n.º 5
0
        /// <include file='doc\GroupBox.uex' path='docs/doc[@for="GroupBox.OnPaint"]/*' />
        /// <internalonly/>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics  graphics      = e.Graphics;
            Rectangle textRectangle = ClientRectangle;

            int textOffset = 8;

            textRectangle.X     += textOffset;
            textRectangle.Width -= 2 * textOffset;

            Brush        textBrush = new SolidBrush(ForeColor);
            StringFormat format    = new StringFormat();

            if (ShowKeyboardCues)
            {
                format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
            }
            else
            {
                format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide;
            }

            // Adjust string format for Rtl controls
            if (RightToLeft == RightToLeft.Yes)
            {
                format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
            }

            Size textSize = Size.Ceiling(graphics.MeasureString(Text, Font, textRectangle.Width, format));

            Color backColor = DisabledColor;

            if (Enabled)
            {
                graphics.DrawString(Text, Font, textBrush, textRectangle, format);
            }
            else
            {
                ControlPaint.DrawStringDisabled(graphics, Text, Font, backColor, textRectangle, format);
            }

            format.Dispose();
            textBrush.Dispose();

            Pen light = new Pen(ControlPaint.Light(backColor, 1.0f));
            Pen dark  = new Pen(ControlPaint.Dark(backColor, 0f));

            int textLeft = textOffset;

            if (RightToLeft == RightToLeft.Yes)
            {
                textLeft = textOffset + textRectangle.Width - textSize.Width;
            }

            int boxTop = FontHeight / 2;

            // left
            graphics.DrawLine(light, 1, boxTop, 1, Height - 1);
            graphics.DrawLine(dark, 0, boxTop, 0, Height - 2);

            // bottom
            graphics.DrawLine(light, 0, Height - 1, Width, Height - 1);
            graphics.DrawLine(dark, 0, Height - 2, Width - 1, Height - 2);

            // top-left
            graphics.DrawLine(dark, 0, boxTop - 1, textLeft, boxTop - 1);
            graphics.DrawLine(light, 1, boxTop, textLeft, boxTop);

            // top-right
            graphics.DrawLine(dark, textLeft + textSize.Width, boxTop - 1, Width - 2, boxTop - 1);
            graphics.DrawLine(light, textLeft + textSize.Width, boxTop, Width - 1, boxTop);

            // right
            graphics.DrawLine(light, Width - 1, boxTop - 1, Width - 1, Height - 1);
            graphics.DrawLine(dark, Width - 2, boxTop, Width - 2, Height - 2);

            // light.Dispose();
            // dark.Dispose();

            base.OnPaint(e); // raise paint event
        }
Ejemplo n.º 6
0
        private void DrawText(Graphics g)
        {
            SolidBrush TextBrush = new SolidBrush(this.ForeColor);

            RectangleF R = (RectangleF)contentRect;

            if (!this.Enabled)
            {
                TextBrush.Color = SystemColors.GrayText;
            }

            StringFormat sf = new StringFormat(StringFormatFlags.NoWrap | StringFormatFlags.NoClip);

            if (ShowKeyboardCues)
            {
                sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
            }
            else
            {
                sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide;
            }

            switch (this.TextAlign)
            {
            case ContentAlignment.TopLeft:
                sf.Alignment     = StringAlignment.Near;
                sf.LineAlignment = StringAlignment.Near;
                break;

            case ContentAlignment.TopCenter:
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Near;
                break;

            case ContentAlignment.TopRight:
                sf.Alignment     = StringAlignment.Far;
                sf.LineAlignment = StringAlignment.Near;
                break;

            case ContentAlignment.MiddleLeft:
                sf.Alignment     = StringAlignment.Near;
                sf.LineAlignment = StringAlignment.Center;
                break;

            case ContentAlignment.MiddleCenter:
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;
                break;

            case ContentAlignment.MiddleRight:
                sf.Alignment     = StringAlignment.Far;
                sf.LineAlignment = StringAlignment.Center;
                break;

            case ContentAlignment.BottomLeft:
                sf.Alignment     = StringAlignment.Near;
                sf.LineAlignment = StringAlignment.Far;
                break;

            case ContentAlignment.BottomCenter:
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Far;
                break;

            case ContentAlignment.BottomRight:
                sf.Alignment     = StringAlignment.Far;
                sf.LineAlignment = StringAlignment.Far;
                break;
            }

            if (this.ButtonState == CustomButtonState.Pressed)
            {
                R.Offset(1, 1);
            }

            if (this.Enabled)
            {
                g.DrawString(this.Text, this.Font, TextBrush, R, sf);
            }
            else
            {
                ControlPaint.DrawStringDisabled(g, this.Text, this.Font, this.BackColor, R, sf);
            }
        }
Ejemplo n.º 7
0
        private void DrawText(Graphics graphics)
        {
            int x      = 0;
            int y      = 2;
            int width  = Width - 2;
            int height = Height - 4;

            int checkSize;

            if (FlatStyle == FlatStyle.Flat)
            {
                checkSize = flatCheckSize;
            }
            else
            {
                checkSize = normalCheckSize;
            }

            SizeF        textSize = graphics.MeasureString(Text, Font);
            StringFormat format   = new StringFormat();

            format.Alignment     = StringAlignment.Near;
            format.LineAlignment = StringAlignment.Far;
            format.HotkeyPrefix  = HotkeyPrefix.Show;

            switch (checkAlign)
            {
            case ContentAlignment.BottomCenter:
                height -= checkSize + 3;
                break;

            case ContentAlignment.BottomLeft:
                x      = checkSize + 3;
                width -= x;
                break;

            case ContentAlignment.BottomRight:
                width -= checkSize;
                break;

            case ContentAlignment.MiddleCenter:
                break;

            case ContentAlignment.MiddleLeft:
                x      = checkSize + 3;
                width -= x;
                break;

            case ContentAlignment.MiddleRight:
                width -= checkSize;
                break;

            case ContentAlignment.TopCenter:
                y       = checkSize + 3;
                height -= y;
                break;

            case ContentAlignment.TopLeft:
                x      = checkSize + 3;
                width -= x;
                break;

            case ContentAlignment.TopRight:
                width -= checkSize;
                break;
            }

            switch (TextAlign)
            {
            case ContentAlignment.BottomCenter:
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Far;
                break;

            case ContentAlignment.BottomLeft:
                format.Alignment     = StringAlignment.Near;
                format.LineAlignment = StringAlignment.Far;
                break;

            case ContentAlignment.BottomRight:
                format.Alignment     = StringAlignment.Far;
                format.LineAlignment = StringAlignment.Far;
                break;

            case ContentAlignment.MiddleCenter:
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
                break;

            case ContentAlignment.MiddleLeft:
                format.LineAlignment = StringAlignment.Center;
                break;

            case ContentAlignment.MiddleRight:
                format.Alignment     = StringAlignment.Far;
                format.LineAlignment = StringAlignment.Center;
                break;

            case ContentAlignment.TopCenter:
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Near;
                break;

            case ContentAlignment.TopLeft:
                format.Alignment     = StringAlignment.Near;
                format.LineAlignment = StringAlignment.Near;
                break;

            case ContentAlignment.TopRight:
                format.Alignment     = StringAlignment.Far;
                format.LineAlignment = StringAlignment.Near;
                break;
            }
            RectangleF rect = new RectangleF(x, y, width, height);
            String     text = Text;
            Font       font = Font;

            if ((TextAlign & (ContentAlignment.MiddleLeft |
                              ContentAlignment.MiddleCenter |
                              ContentAlignment.MiddleRight)) != 0)
            {
                rect.Offset(0.0f, GetDescent(graphics, font) / 2.0f);
            }
            if (text != null && text != String.Empty)
            {
                if (Enabled)
                {
                    Brush brush = new SolidBrush(ForeColor);
                    graphics.DrawString(text, font, brush, rect, format);
                    brush.Dispose();
                }
                else
                {
                    ControlPaint.DrawStringDisabled
                        (graphics, text, font, BackColor, rect, format);
                }
            }
        }
Ejemplo n.º 8
0
        // Draw the button in its current state on a Graphics surface.
        internal virtual void Draw(Graphics graphics)
        {
            ButtonState state      = CalculateState();
            Size        clientSize = ClientSize;
            int         x          = 0;
            int         y          = 0;
            int         width      = clientSize.Width;
            int         height     = clientSize.Height;

            // Draw the border and background.
            ThemeManager.MainPainter.DrawButton
                (graphics, x, y, width, height, state,
                ForeColor, BackColor, isDefault);

            // Draw the focus rectangle.
            if (hasFocus)
            {
                ControlPaint.DrawFocusRectangle
                    (graphics, new Rectangle(x + 4, y + 4,
                                             width - 8, height - 8),
                    ForeColor, BackColor);
            }

            // Draw the button image.
            Image image = this.image;

            if (image == null && imageList != null && imageIndex != -1)
            {
                image = imageList.Images[imageIndex];
            }
            if (image != null)
            {
                int imageX      = x;
                int imageY      = y;
                int imageWidth  = image.Width;
                int imageHeight = image.Height;
                switch (imageAlign)
                {
                case ContentAlignment.TopLeft: break;

                case ContentAlignment.TopCenter:
                {
                    imageX += (width - imageWidth) / 2;
                }
                break;

                case ContentAlignment.TopRight:
                {
                    imageX += width - imageWidth;
                }
                break;

                case ContentAlignment.MiddleLeft:
                {
                    imageY += (height - imageHeight) / 2;
                }
                break;

                case ContentAlignment.MiddleCenter:
                {
                    imageX += (width - imageWidth) / 2;
                    imageY += (height - imageHeight) / 2;
                }
                break;

                case ContentAlignment.MiddleRight:
                {
                    imageX += width - imageWidth;
                    imageY += (height - imageHeight) / 2;
                }
                break;

                case ContentAlignment.BottomLeft:
                {
                    imageY += height - imageHeight;
                }
                break;

                case ContentAlignment.BottomCenter:
                {
                    imageX += (width - imageWidth) / 2;
                    imageY += height - imageHeight;
                }
                break;

                case ContentAlignment.BottomRight:
                {
                    imageX += width - imageWidth;
                    imageY += height - imageHeight;
                }
                break;
                }
                if (pressed)
                {
                    ++imageX;
                    ++imageY;
                }
                if (Enabled)
                {
                    graphics.DrawImage(image, imageX, imageY);
                }
                else
                {
                    ControlPaint.DrawImageDisabled
                        (graphics, image, imageX, imageY, BackColor);
                }
            }

            // Get the text layout rectangle.
            RectangleF layout = new RectangleF
                                    (x + 2, y + 2, width - 4, height - 4);

            if (entered && pressed)
            {
                layout.Offset(1.0f, 1.0f);
            }

            // If we are using "middle" alignment, then shift the
            // text down to account for the descent.  This makes
            // the button "look better".
            Font font = Font;

            if ((TextAlign & (ContentAlignment.MiddleLeft |
                              ContentAlignment.MiddleCenter |
                              ContentAlignment.MiddleRight)) != 0)
            {
                layout.Offset(0.0f, GetDescent(graphics, font) / 2.0f);
            }

            // Draw the text on the button.
            String text = Text;

            if (text != null && text != String.Empty)
            {
                if (Enabled)
                {
                    Brush brush = new SolidBrush(ForeColor);
                    graphics.DrawString(text, font, brush, layout, format);
                    brush.Dispose();
                }
                else
                {
                    ControlPaint.DrawStringDisabled
                        (graphics, text, font, BackColor, layout, format);
                }
            }
        }
Ejemplo n.º 9
0
        // Draw the button in its current state on a Graphics surface.
        internal override void Draw(Graphics graphics)
        {
            // calculate ButtonState needed by DrawRadioButton
            ButtonState  state  = CalculateState();
            StringFormat format = GetStringFormat();

            if (needsLayout)
            {
                LayoutElements();
            }

            if (appearance == Appearance.Button)
            {
                ThemeManager.MainPainter.DrawButton
                    (graphics, 0, 0, content.Width, content.Height,
                    state, ForeColor, BackColor, false);
            }
            else
            {
                using (Brush bg = CreateBackgroundBrush())
                {
                    ThemeManager.MainPainter.DrawRadioButton
                        (graphics, checkX, checkY, checkSize, checkSize,
                        state, ForeColor, BackColor, bg);
                }
            }

            // TODO: image drawing

            Rectangle rect = content;

            if (appearance == Appearance.Button)
            {
                int x      = content.X;
                int y      = content.Y;
                int width  = content.Width;
                int height = content.Height;
                x      += 2;
                y      += 2;
                width  -= 4;
                height -= 4;
                if ((state & ButtonState.Pushed) != 0)
                {
                    ++x;
                    ++x;
                }
                rect = new Rectangle(x, y, width, height);
            }
            RectangleF layout = rect;
            Font       font   = Font;

            if ((TextAlign & (ContentAlignment.MiddleLeft |
                              ContentAlignment.MiddleCenter |
                              ContentAlignment.MiddleRight)) != 0)
            {
                layout.Offset(0.0f, GetDescent(graphics, font) / 2.0f);
            }
            if (Enabled)
            {
                using (Brush brush = new SolidBrush(ForeColor))
                {
                    graphics.DrawString(Text, font, brush, layout, format);
                }
            }
            else
            {
                ControlPaint.DrawStringDisabled(graphics, Text, font, BackColor, layout, format);
            }
        }
Ejemplo n.º 10
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Color nearestColor;

            this.Animate();
            Rectangle r = LayoutUtils.DeflateRect(base.ClientRectangle, base.Padding);

            ImageAnimator.UpdateFrames();
            System.Drawing.Image image = this.Image;
            if (image != null)
            {
                this.DrawImage(e.Graphics, image, r, base.RtlTranslateAlignment(this.ImageAlign));
            }
            IntPtr hdc = e.Graphics.GetHdc();

            try
            {
                using (WindowsGraphics graphics = WindowsGraphics.FromHdc(hdc))
                {
                    nearestColor = graphics.GetNearestColor(base.Enabled ? this.ForeColor : base.DisabledColor);
                }
            }
            finally
            {
                e.Graphics.ReleaseHdc();
            }
            if (this.AutoEllipsis)
            {
                Rectangle clientRectangle = base.ClientRectangle;
                Size      preferredSize   = this.GetPreferredSize(new Size(clientRectangle.Width, clientRectangle.Height));
                this.showToolTip = (clientRectangle.Width < preferredSize.Width) || (clientRectangle.Height < preferredSize.Height);
            }
            else
            {
                this.showToolTip = false;
            }
            if (this.UseCompatibleTextRendering)
            {
                using (StringFormat format = this.CreateStringFormat())
                {
                    if (base.Enabled)
                    {
                        using (Brush brush = new SolidBrush(nearestColor))
                        {
                            e.Graphics.DrawString(this.Text, this.Font, brush, r, format);
                            goto Label_01BF;
                        }
                    }
                    ControlPaint.DrawStringDisabled(e.Graphics, this.Text, this.Font, nearestColor, r, format);
                    goto Label_01BF;
                }
            }
            TextFormatFlags flags = this.CreateTextFormatFlags();

            if (base.Enabled)
            {
                TextRenderer.DrawText(e.Graphics, this.Text, this.Font, r, nearestColor, flags);
            }
            else
            {
                Color foreColor = TextRenderer.DisabledTextColor(this.BackColor);
                TextRenderer.DrawText(e.Graphics, this.Text, this.Font, r, foreColor, flags);
            }
Label_01BF:
            base.OnPaint(e);
        }