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); }
/// <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 }
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); }