Ejemplo n.º 1
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);
        }