/// <summary></summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { //For Desktop: //Always call base.OnPaint() to let the Framework render the border and the box. //Image is always to be rendered by the Framework. //If Image is not available, then only... //1. Appearance=Normal, just draw the text. //2. Appearance=Button, paint the background and text. //Since we do not want the Framework to paint the Text, set it to "" (blank) before calling base.OnPaint() and //reset it later. String orgText = Text; TextToDisplay = Text; base.Text = String.Empty; if (BackColor == Color.Transparent && Parent is ISupportsTransparentChildRendering) { ((ISupportsTransparentChildRendering)Parent).TransparentChild = this; } base.OnPaint(e); if (BackColor == Color.Transparent && Parent is ISupportsTransparentChildRendering) { ((ISupportsTransparentChildRendering)Parent).TransparentChild = null; } base.Text = orgText; //Since we are modifying the Text, we need to Validate the Rect. Otherwise, the paint will go in recursion. win32.NativeWindowCommon.ValidateRect(this.Handle, IntPtr.Zero); if (Image == null) { if (Appearance == Appearance.Normal) { Rectangle textRect = new Rectangle(); textRect = ClientRectangle; //Padding also includes the padding set for the BOX. But it is not needed while rendering the text. //So, ignore it. textRect.Location = new Point(textRect.Left + Padding.Left, textRect.Top + Padding.Top - checkTopPadding); textRect.Size = new Size(textRect.Width - (Padding.Left + Padding.Right), textRect.Height - (Padding.Top + Padding.Bottom - checkTopPadding)); CheckBoxAndRadioButtonRenderer.DrawTextAndFocusRect(this, e, TextToDisplay, textRect, textOffset); } else { ButtonRenderer.DrawButton(this, e, true, true); } } else { if (Focused && Appearance == Appearance.Normal) { CheckBoxAndRadioButtonRenderer.DrawFocusRectOnCheckBoxGlyph(this, e.Graphics); } } // paint the border if (BorderType != BorderType.NoBorder) { BorderRenderer.PaintBorder(e.Graphics, ClientRectangle, ForeColor, ControlStyle.TwoD, false, BorderType); } }