protected override void OnPaint(PaintEventArgs e) { //Simulate Transparency if (BackColor == Color.Transparent) { #if !PocketPC if (Parent is ISupportsTransparentChildRendering) { ((ISupportsTransparentChildRendering)Parent).TransparentChild = this; } System.Drawing.Drawing2D.GraphicsContainer g = e.Graphics.BeginContainer(); Rectangle translateRect = this.Bounds; e.Graphics.TranslateTransform(-Left, -Top); PaintEventArgs pe = new PaintEventArgs(e.Graphics, translateRect); this.InvokePaintBackground(Parent, pe); this.InvokePaint(Parent, pe); //fixed bug#:796041, the forgound not need to display //this.InvokePaint(Parent, pe); e.Graphics.ResetTransform(); e.Graphics.EndContainer(g); pe.Dispose(); if (Parent is ISupportsTransparentChildRendering) { ((ISupportsTransparentChildRendering)Parent).TransparentChild = null; } #endif } ControlRenderer.FillRectAccordingToGradientStyle(e.Graphics, ClientRectangle, BackColor, LinkColor, 0, false, GradientColor, GradientStyle); ContentAlignment newTextAlign = ControlUtils.GetOrgContentAligment(RightToLeft, TextAlign); FontDescription font = new FontDescription(Font); ControlRenderer.PrintText(e.Graphics, ClientRectangle, LinkColor, font, Text, false, newTextAlign, Enabled, true, !UseMnemonic, false, (RightToLeft == RightToLeft.Yes)); //fixed bug #:765815 : when parking on hypertext button,focus need to seen on text on the button (not on entire button) if (Focused) { Size textExt = Utils.GetTextExt(Font, Text, this); // get the display the focus on the text of the control Rectangle textRect = ControlUtils.GetFocusRect(this, ClientRectangle, newTextAlign, textExt); //ass offset, it will look as in online textRect.Inflate(2, 2); textRect.Width -= 2; textRect.Height -= 1; textRect.X = Math.Max(1, textRect.X); textRect.Y = Math.Max(1, textRect.Y); textRect.Width = Math.Min(textRect.Width, ClientRectangle.Width - textRect.X); textRect.Height = Math.Min(textRect.Height, ClientRectangle.Height - textRect.Y); ControlPaint.DrawFocusRectangle(e.Graphics, textRect); } }
/// <summary> /// Draw the text and the focus rectangle on a CheckBox/RadioButon control. /// </summary> /// <param name="control"></param> /// <param name="e"></param> /// <param name="textToDisplay"></param> public static void DrawTextAndFocusRect(ButtonBase control, PaintEventArgs e, String textToDisplay, Rectangle rectangle, int textOffset) { bool isMultiLine = ControlUtils.GetIsMultiLine(control); Rectangle textRect = new Rectangle(); Size textSize = new Size(); ContentAlignment NewTextAli = ContentAlignment.MiddleCenter; FontDescription font = new FontDescription(control.Font); if (!String.IsNullOrEmpty(textToDisplay)) { textRect = rectangle; NewTextAli = ControlUtils.GetOrgContentAligment(control.RightToLeft, control.TextAlign); textSize = Utils.GetTextExt(control.Font, textToDisplay, control); ControlUtils.AlignmentInfo AlignmentInfo = ControlUtils.GetAlignmentInfo(control.TextAlign); int Offset = (int)((float)(BOX_WIDTH + textOffset) * Utils.GetDpiScaleRatioX(control)); switch (AlignmentInfo.HorAlign) { case AlignmentTypeHori.Left: if (control.RightToLeft == RightToLeft.No) { textRect.X += Offset; textRect.Width -= Offset; } if (control.RightToLeft == RightToLeft.Yes) { textRect.X -= Offset; } break; case AlignmentTypeHori.Right: if (isMultiLine && control.RightToLeft == RightToLeft.No) { textRect.X += Offset; textRect.Width -= Offset; } break; case AlignmentTypeHori.Center: if (control.RightToLeft == RightToLeft.No) { textRect.X += Offset; textRect.Width -= Offset; // if the text is bigger then the display rect. if (!isMultiLine) { if (textSize.Width > textRect.Width) { textRect.X += (int)(((textRect.Width - textSize.Width) / 2)); textRect.Width = Math.Max(textRect.Width, textSize.Width); } } } else if (control.RightToLeft == RightToLeft.Yes) { textRect.X -= Offset; textRect.Width += Offset; } break; } ControlRenderer.PrintText(e.Graphics, textRect, control.ForeColor, font, textToDisplay, isMultiLine, NewTextAli, control.Enabled, true, false, true, control.RightToLeft == RightToLeft.Yes, true); } // display the focus on the text of the control if (control.Focused) { if (!String.IsNullOrEmpty(textToDisplay)) { if (isMultiLine) { textSize = GetTextSize(e, textToDisplay, font, ref textRect, isMultiLine); } // get the display the focus on the text of the control textRect = ControlUtils.GetFocusRect(control, textRect, NewTextAli, textSize); ControlPaint.DrawFocusRectangle(e.Graphics, textRect); } else { //For CheckBox, if the text is not available, focus rect should be drawn on the Glyph. if (control is MgCheckBox) { DrawFocusRectOnCheckBoxGlyph((MgCheckBox)control, e.Graphics); } } } }