/// <summary> /// /// </summary> /// <param name="graphics"></param> /// <param name="rect"></param> private void DrawBackground(Graphics graphics, Rectangle rect) { Color bgColorToUse = (Parent is TableControl) ? ((TableControl)Parent).GetBGColorToUse(this) : BackColor; ControlRenderer.FillRectAccordingToGradientStyle(graphics, rect, bgColorToUse, ForeColor, Style, false, GradientColor, GradientStyle, BorderType); }
/// <summary> /// /// </summary> /// <param name="pevent"></param> protected override void OnPaintBackground(PaintEventArgs pevent) { //Simulate Transparency if (BackColor == Color.Transparent || BackColor.A < 255) { if (Parent is ISupportsTransparentChildRendering) { ((ISupportsTransparentChildRendering)Parent).TransparentChild = this; } System.Drawing.Drawing2D.GraphicsContainer g = pevent.Graphics.BeginContainer(); Rectangle translateRect = this.Bounds; pevent.Graphics.TranslateTransform(-Left, -Top); PaintEventArgs pe = new PaintEventArgs(pevent.Graphics, translateRect); this.InvokePaintBackground(Parent, pe); this.InvokePaint(Parent, pe); pevent.Graphics.ResetTransform(); pevent.Graphics.EndContainer(g); pe.Dispose(); if (Parent is ISupportsTransparentChildRendering) { ((ISupportsTransparentChildRendering)Parent).TransparentChild = null; } } ControlRenderer.FillRectAccordingToGradientStyle(pevent.Graphics, this.ClientRectangle, BackColor, ForeColor, ControlStyle.NoBorder, false, GradientColor, GradientStyle); if (TransparentChild != null && DesignMode) { ControlRenderer.RenderOwnerDrawnControlsOfParent(pevent.Graphics, TransparentChild); } }
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> paint control backgound and image</summary> /// <param name="control"></param> /// <param name="graphics"></param> /// <param name="useImageSize" - do the image will be display on all the control (for button image)></param> /// <param name="DisplayRect" - the display rect of the color></param> public static void PaintBackgoundColorAndImage(Control control, Graphics graphics, bool useImageSize, Rectangle DisplayRect) { Image backgroundImage = null; GradientColor gradientColor = ControlUtils.GetGradientColor(control); GradientStyle gradientStyle = ControlUtils.GetGradientStyle(control); ControlRenderer.FillRectAccordingToGradientStyle(graphics, DisplayRect, control.BackColor, control.ForeColor, ControlStyle.NoBorder, false, gradientColor, gradientStyle); #if !PocketPC backgroundImage = control.BackgroundImage; #else if (control is ButtonBase) { ButtonBase button = (ButtonBase)control; backgroundImage = button.BackgroundImage; } else if (control is MgPanel) { MgPanel panel = (MgPanel)control; backgroundImage = panel.BackGroundImage; } #endif if (backgroundImage != null) { Rectangle rectImage; if (useImageSize) { rectImage = new Rectangle(DisplayRect.X, DisplayRect.Y, backgroundImage.Width, backgroundImage.Height); } else { rectImage = control.ClientRectangle; } DrawImage(graphics, rectImage, backgroundImage, 0, 0); } }