protected override void OnPaint(PaintEventArgs e)
 {
     if ((Application.RenderWithVisualStyles && (base.Width >= 10)) && (base.Height >= 10))
     {
         GroupBoxState   state = base.Enabled ? GroupBoxState.Normal : GroupBoxState.Disabled;
         TextFormatFlags flags = TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak;
         if (!this.ShowKeyboardCues)
         {
             flags |= TextFormatFlags.HidePrefix;
         }
         if (this.RightToLeft == RightToLeft.Yes)
         {
             flags |= TextFormatFlags.RightToLeft | TextFormatFlags.Right;
         }
         if (this.ShouldSerializeForeColor() || !base.Enabled)
         {
             Color textColor = base.Enabled ? this.ForeColor : TextRenderer.DisabledTextColor(this.BackColor);
             GroupBoxRenderer.DrawGroupBox(e.Graphics, new Rectangle(0, 0, base.Width, base.Height), this.Text, this.Font, textColor, flags, state);
         }
         else
         {
             GroupBoxRenderer.DrawGroupBox(e.Graphics, new Rectangle(0, 0, base.Width, base.Height), this.Text, this.Font, flags, state);
         }
     }
     else
     {
         this.DrawGroupBox(e);
     }
     base.OnPaint(e);
 }
Ejemplo n.º 2
0
        /// <include file='doc\GroupBox.uex' path='docs/doc[@for="GroupBox.OnPaint"]/*' />
        /// <internalonly/>
        protected override void OnPaint(PaintEventArgs e)
        {
            // BACKCOMPAT requirement:
            // Why the Height/Width >= 10 check? This is because uxtheme doesn't seem to handle those cases
            // similar to what we do for the non-themed case, so if someone is using the groupbox as a
            // separator, their app will look weird in Whidbey. We render the old way in these cases.

            if (Application.RenderWithVisualStyles && Width >= 10 && Height >= 10)
            {
                GroupBoxState   gbState   = Enabled ? GroupBoxState.Normal : GroupBoxState.Disabled;
                TextFormatFlags textFlags = TextFormatFlags.Default | TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping;

                if (!ShowKeyboardCues)
                {
                    textFlags |= TextFormatFlags.HidePrefix;
                }

                if (RightToLeft == RightToLeft.Yes)
                {
                    textFlags |= (TextFormatFlags.Right | TextFormatFlags.RightToLeft);
                }

                // We only pass in the text color if it is explicitly set, else we let the renderer use the
                // color specified by the theme. This is a temporary workaround till we find a good
                // solution for the "default theme color" issue.
                if (ShouldSerializeForeColor() || this.Enabled == false)
                {
                    Color textcolor = this.Enabled ? ForeColor : TextRenderer.DisabledTextColor(this.BackColor);
                    GroupBoxRenderer.DrawGroupBox(e.Graphics, new Rectangle(0, 0, Width, Height), Text, Font, textcolor, textFlags, gbState);
                }
                else
                {
                    GroupBoxRenderer.DrawGroupBox(e.Graphics, new Rectangle(0, 0, Width, Height), Text, Font, textFlags, gbState);
                }
            }
            else
            {
                DrawGroupBox(e);
            }
            base.OnPaint(e); // raise paint event
        }