/// <summary>This method will paint the group title.</summary> /// <param name="g">The paint event graphics object.</param> private void PaintGroupText(System.Drawing.Graphics g) { //Check if string has something------------- if (this.GroupTitle == string.Empty) { return; } //------------------------------------------ //Set Graphics smoothing mode to Anit-Alias-- g.SmoothingMode = SmoothingMode.AntiAlias; //------------------------------------------- //Declare Variables------------------ SizeF StringSize = g.MeasureString(this.GroupTitle, this.Font); Size StringSize2 = StringSize.ToSize(); if (this.GroupImage != null) { StringSize2.Width += 18; } int ArcWidth = this.RoundCorners; int ArcHeight = this.RoundCorners; int ArcX1 = 20; int ArcX2 = (StringSize2.Width + 34) - (ArcWidth + 1); int ArcY1 = 0; int ArcY2 = 24 - (ArcHeight + 1); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = (this.PaintGroupBox) ? new SolidBrush(this.CustomGroupBoxColor) : new SolidBrush(this.BackgroundColor); System.Drawing.SolidBrush TextColorBrush = new SolidBrush(this.ForeColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //----------------------------------- //Check if shadow is needed---------- if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left ShadowPath.CloseAllFigures(); //Paint Rounded Rectangle------------ g.FillPath(ShadowBrush, ShadowPath); //----------------------------------- } //----------------------------------- //Create Rounded Rectangle Path------ path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left path.CloseAllFigures(); //----------------------------------- //Check if Gradient Mode is enabled-- if (this.PaintGroupBox) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { if (this.BackgroundGradientMode == GroupBoxGradientMode.None) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); //Paint Rounded Rectangle------------ g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } } //----------------------------------- //Paint Borded----------------------- g.DrawPath(BorderPen, path); //----------------------------------- //Paint Text------------------------- int CustomStringWidth = (this.GroupImage != null) ? 44 : 28; g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth, 5); //----------------------------------- //Draw GroupImage if there is one---- if (this.GroupImage != null) { g.DrawImage(this.GroupImage, 28, 4, 16, 16); } //----------------------------------- //Destroy Graphic Objects------------ if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderBrush.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (TextColorBrush != null) { TextColorBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } //----------------------------------- }
/// <summary>This method will paint the control.</summary> /// <param name="g">The paint event graphics object.</param> private void PaintBack(System.Drawing.Graphics g) { //Set Graphics smoothing mode to Anit-Alias-- g.SmoothingMode = SmoothingMode.AntiAlias; //------------------------------------------- //Declare Variables------------------ int ArcWidth = this.RoundCorners * 2; int ArcHeight = this.RoundCorners * 2; int ArcX1 = 0; int ArcX2 = (this.ShadowControl) ? (this.Width - (ArcWidth + 1)) - this.ShadowThickness : this.Width - (ArcWidth + 1); int ArcY1 = 10; int ArcY2 = (this.ShadowControl) ? (this.Height - (ArcHeight + 1)) - this.ShadowThickness : this.Height - (ArcHeight + 1); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = new SolidBrush(this.BackgroundColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //----------------------------------- //Check if shadow is needed---------- if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left ShadowPath.CloseAllFigures(); //Paint Rounded Rectangle------------ g.FillPath(ShadowBrush, ShadowPath); //----------------------------------- } //----------------------------------- //Create Rounded Rectangle Path------ path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left path.CloseAllFigures(); //----------------------------------- //Check if Gradient Mode is enabled-- if (this.BackgroundGradientMode == GroupBoxGradientMode.None) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); //Paint Rounded Rectangle------------ g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } //----------------------------------- //Paint Borded----------------------- g.DrawPath(BorderPen, path); //----------------------------------- //Destroy Graphic Objects------------ if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderBrush.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } //----------------------------------- }
/// <summary>This method will paint the group title.</summary> /// <param name="g">The paint event graphics object.</param> private void PaintGroupText(System.Drawing.Graphics g) { //Check if string has something------------- if (this.GroupTitle == string.Empty) { return; } //------------------------------------------ //Set Graphics smoothing mode to Anit-Alias-- g.SmoothingMode = SmoothingMode.AntiAlias; //------------------------------------------- //Declare Variables------------------ SizeF StringSize = g.MeasureString(this.GroupTitle, this.Font); Size StringSize2 = StringSize.ToSize(); if (this.GroupImage != null) { StringSize2.Width += 18; } int ArcWidth = this.RoundCorners; int ArcHeight = this.RoundCorners; int ArcX1 = 28 + GroupTitleOffset.X - 4; int ArcX2 = (StringSize2.Width + 34) - (ArcWidth + 1) + GroupTitleOffset.X; int ArcY1 = GroupTitleOffset.Y + 3; int ArcY2 = 24 - (ArcHeight + 1) + GroupTitleOffset.Y - 2; if (this.GroupTitleType == GroupTitleRenderType.Fill) { ArcX1 = 0 + GroupTitleOffset.X; // 20; ArcX2 = this.Width - 3 + GroupTitleOffset.X; // (StringSize2.Width + 34) - (ArcWidth + 1); ArcY1 = GroupTitleOffset.Y; // 0 ArcY2 = 24 - (ArcHeight + 7) + GroupTitleOffset.Y; // + 1 } System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = (this.PaintGroupBox) ? new SolidBrush(this.CustomGroupBoxColor) : new SolidBrush(this.BackgroundColor); System.Drawing.SolidBrush TextColorBrush = new SolidBrush(this.ForeColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //----------------------------------- //Check if shadow is needed---------- if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 180, SweepAngle); // Top Left ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 270, SweepAngle); //Top Right ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 360, SweepAngle); //Bottom Right ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 90, SweepAngle); //Bottom Left ShadowPath.CloseAllFigures(); //Paint Rounded Rectangle------------ g.FillPath(ShadowBrush, ShadowPath); //----------------------------------- } //----------------------------------- //Create Rounded Rectangle Path------ path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, SweepAngle); // Top Left path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, SweepAngle); //Top Right path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, SweepAngle); //Bottom Right path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, SweepAngle); //Bottom Left path.CloseAllFigures(); //----------------------------------- //Check if Gradient Mode is enabled-- if (this.PaintGroupBox) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { if (this.BackgroundGradientMode == GroupBoxGradientMode.None) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); //Paint Rounded Rectangle------------ g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } } //----------------------------------- //Paint Borded----------------------- if (this.GroupBoxBorder == GroupBoxBorderType.Full) { g.DrawPath(BorderPen, path); } else if (this.GroupBoxBorder == GroupBoxBorderType.HalfTop) { System.Drawing.Drawing2D.GraphicsPath halfPath2 = new System.Drawing.Drawing2D.GraphicsPath(); halfPath2.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, SweepAngle); // Top Left halfPath2.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, SweepAngle); //Top Right halfPath2.AddArc(ArcX2, ArcY1 + (ArcY2 - ArcY1) * 0.5f, ArcWidth, ArcHeight, 360, SweepAngle); //Bottom Right halfPath2.AddArc(ArcX1, ArcY1 + (ArcY2 - ArcY1) * 0.5f, ArcWidth, ArcHeight, 90, SweepAngle); //Bottom Left halfPath2.CloseAllFigures(); g.DrawPath(BorderPen, halfPath2); g.FillRectangle(BackgroundBrush, ArcX1 - 1, ArcY1 + (ArcY2 - ArcY1) * 0.5f + 1, ArcX2, this.BorderThickness + 2); } //----------------------------------- //Paint Text------------------------- int CustomStringWidth = (this.GroupImage != null) ? 46 : 28; if (this.GroupTitleType == GroupTitleRenderType.Fill) { g.DrawString(this.GroupTitle, this.Font, TextColorBrush, (int)((this.Width * 0.5) - (StringSize2.Width * 0.5)) + GroupTitleOffset.X, 1 + GroupTitleOffset.Y); // 5 } else if (this.GroupTitleType == GroupTitleRenderType.Standard) { g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth + GroupTitleOffset.X, 5 + GroupTitleOffset.Y - 1); } //----------------------------------- //Draw GroupImage if there is one---- if (this.GroupImage != null) { g.DrawImage(this.GroupImage, 30 + GroupTitleOffset.X, 4 + GroupTitleOffset.Y, 16, 16); } //----------------------------------- //Destroy Graphic Objects------------ if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderBrush.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (TextColorBrush != null) { TextColorBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } //----------------------------------- }
/// <summary>This method will paint the control.</summary> /// <param name="g">The paint event graphics object.</param> private void PaintBack(System.Drawing.Graphics g) { //Set Graphics smoothing mode to Anit-Alias-- g.SmoothingMode = SmoothingMode.AntiAlias; //------------------------------------------- //Declare Variables------------------ int ArcWidth = this.RoundCorners * 2; int ArcHeight = this.RoundCorners * 2; int ArcX1 = 0; int ArcX2 = (this.ShadowControl) ? (this.Width - (ArcWidth + 1)) - this.ShadowThickness : this.Width - (ArcWidth + 1); int ArcY1 = 10; //Check if string has something------------- if (this.GroupTitle == string.Empty) { ArcY1 = 0; } //------------------------------------------ int ArcY2 = (this.ShadowControl) ? (this.Height - (ArcHeight + 1)) - this.ShadowThickness : this.Height - (ArcHeight + 1); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = new SolidBrush(this.BackgroundColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //----------------------------------- //Check if shadow is needed---------- if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, SweepAngle); // Top Left ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, SweepAngle); //Top Right ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, SweepAngle); //Bottom Right ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, SweepAngle); //Bottom Left ShadowPath.CloseAllFigures(); //Paint Rounded Rectangle------------ g.FillPath(ShadowBrush, ShadowPath); //----------------------------------- } //----------------------------------- //Create Rounded Rectangle Path------ path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, SweepAngle); // Top Left path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, SweepAngle); //Top Right path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, SweepAngle); //Bottom Right path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, SweepAngle); //Bottom Left path.CloseAllFigures(); //----------------------------------- //Check if Gradient Mode is enabled-- if (this.BackgroundGradientMode == GroupBoxGradientMode.None) { //Paint Rounded Rectangle------------ if (this.GroupBoxDrawStyle == GroupBoxDrawType.SingleLine) { g.FillPath(BackgroundBrush, path); } else { Brush brush1 = null; Brush brush2 = null; if (this.GroupBoxDrawStyle == GroupBoxDrawType.TwoLine) { brush1 = BackgroundBrush; brush2 = new SolidBrush(BackgroundColor2); } else if (this.GroupBoxDrawStyle == GroupBoxDrawType.TwoLineReversed) { brush1 = new SolidBrush(BackgroundColor2); brush2 = BackgroundBrush; } int dis = ArcY2 - ArcY1; int num = dis / TwoLineDistance; int curY = TwoLineStartOffset; GraphicsPath twoLinePath = new GraphicsPath(); for (int i = 0; i < num; ++i) { if (i % 2 == 0) { g.FillRectangle(brush1, ArcX1 + 1, curY, ArcX2 + 2, TwoLineDistance); } else if (i % 2 == 1) { g.FillRectangle(brush2, ArcX1 + 1, curY, ArcX2 + 2, TwoLineDistance); } curY += TwoLineDistance; } } //----------------------------------- } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); //Paint Rounded Rectangle------------ g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } //----------------------------------- //Paint Borded----------------------- g.DrawPath(BorderPen, path); //----------------------------------- //Destroy Graphic Objects------------ if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderBrush.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } //----------------------------------- }
public void Draw(Graphics g) { g.SmoothingMode = SmoothingMode.AntiAlias; int ArcWidth = this.C_RoundCorners * 2; int ArcHeight = this.C_RoundCorners * 2; int ArcX1 = Rect.Left; int ArcX2 = (this.ShadowControl) ? (Rect.Left + Rect.Width - (ArcWidth + 1)) - this.ShadowThickness : Rect.Left + Rect.Width - (ArcWidth + 1); int ArcY1 = Rect.Top; int ArcY2 = (this.ShadowControl) ? (Rect.Top + Rect.Height - (ArcHeight + 1)) - this.ShadowThickness : Rect.Top + Rect.Height - (ArcHeight + 1); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(Color.Orange); System.Drawing.Pen BorderPen = new Pen(BorderBrush, 2.0f); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = new SolidBrush(Color.White); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //画出阴影效果 if (this.ShadowControl) { Color shadowColor = Color.FromArgb(192, this.ShadowColor); //说明:1-(128/255)=1-0.5=0.5 透明度为0.5,即50% ShadowBrush = new SolidBrush(shadowColor); //ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, SweepAngle); //顶端的左角 ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, SweepAngle); //顶端右角 ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, SweepAngle); //底部右角 ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, SweepAngle); //底部左角 ShadowPath.CloseAllFigures(); g.FillPath(ShadowBrush, ShadowPath); } //画出图形 path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, SweepAngle); path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, SweepAngle); path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, SweepAngle); path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, SweepAngle); path.CloseAllFigures(); if (this.C_BackgroundGradientMode == DutBoxGradientMode.None) { BackgroundBrush = new SolidBrush(this.BackgroundGradientColor); g.FillPath(BackgroundBrush, path); } else { Color startColor = Color.FromArgb(192, Color.White); BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(Rect.Left, Rect.Top, Rect.Width, Rect.Height), startColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); g.FillPath(BackgroundGradientBrush, path); } //画边框 if (Focus) { g.DrawPath(BorderPen, path); } else { System.Drawing.Brush defaultBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen defaultPen = new Pen(defaultBrush, this.BorderThickness); g.DrawPath(defaultPen, path); if (defaultBrush != null) { defaultBrush.Dispose(); } if (defaultPen != null) { defaultPen.Dispose(); } } //画内容 ID Font font = new Font("Arial", 14.25F, System.Drawing.FontStyle.Bold); g.DrawString((ID + 1).ToString(), font, Brushes.Black, Rect.Left + 6, Rect.Top + 6); if (Connected) { //画状态 if (!string.IsNullOrEmpty(Status)) { font = new Font("Arial", 11.25F, FontStyle.Bold); g.DrawString(Status, font, Brushes.Black, Rect.Left + 6 + 56, Rect.Top + 6 + 2); } //画进度条 Rectangle bar = new Rectangle(Rect.Left + 6, Rect.Top + 28, Rect.Width - 10, 14); ProgressBar.Rect = bar; g.SmoothingMode = SmoothingMode.Default; ProgressBar.Draw(g); g.SmoothingMode = SmoothingMode.AntiAlias; /* Button but = new Button( ); * but.Text = "打印"; * but.Location = new Point(Rect.Width - 5,14);*/ //画打印图标 20161223 bonnie string haarXmlPath = @"../../打印图标.png"; FileInfo file = new FileInfo(haarXmlPath); string fullName = file.FullName; //画SN if (!string.IsNullOrEmpty(SerialNumber)) { font = new Font("Arial", 10.25F); g.DrawString("SN:" + SerialNumber, font, Brushes.Black, Rect.Left + 6, Rect.Top + 6 + 40); } //画IMEI if (!string.IsNullOrEmpty(IMEI)) { font = new Font("Arial", 10.25F); g.DrawString("IMEI:" + IMEI, font, Brushes.Black, Rect.Left + 6, Rect.Top + 6 + 60); } font = new Font("Arial", 10.25F, FontStyle.Bold); //画time if (ElapsedTime > 0.0f) { g.DrawString((int)ElapsedTime + "/" + (int)EstimateTime, font, Brushes.Black, Rect.Left + 6, Rect.Top + 6 + 80); } //画测试方式 switch (Way) { case TestWay.TW_AUTO: g.DrawString("Auto", font, Brushes.DarkGreen, Rect.Left + 6 + 90, Rect.Top + 6 + 80); break; case TestWay.TW_MANUAL: g.DrawString("Manual", font, Brushes.Red, Rect.Left + 6 + 80, Rect.Top + 6 + 80); break; case TestWay.TW_NONE: break; } //画Model if (!string.IsNullOrEmpty(Model)) { font = new Font("Arial", 10.25F); g.DrawString(Model, font, Brushes.Black, Rect.Left + 6, Rect.Top + 6 + 100); } //画QRCode 48 x 48 if (QRCode != null) { bar = new Rectangle(Rect.Right - 58, Rect.Top + 84, 48, 48); //g.FillRectangle(Brushes.Red, bar); g.SmoothingMode = SmoothingMode.None; g.DrawImageUnscaled(QRCode, bar); g.SmoothingMode = SmoothingMode.AntiAlias; } if (QRCode != null) { FileInfo image_file = new FileInfo($@"./pictures/打印图标.png"); if (image_file.Exists) { PrintIocnImage = Image.FromFile(image_file.FullName); g.SmoothingMode = SmoothingMode.None; g.DrawImage(PrintIocnImage, Rect.Right - 98, Rect.Top + 104); g.SmoothingMode = SmoothingMode.AntiAlias; } } } else // disconnected - TESTING & FAIL { if (Result == ItemResult.IR_TESTING) { StringFormat stringFormat = new StringFormat(); stringFormat.LineAlignment = StringAlignment.Center; stringFormat.Alignment = StringAlignment.Center; stringFormat.FormatFlags = StringFormatFlags.LineLimit; stringFormat.Trimming = StringTrimming.EllipsisCharacter; font = new Font("Arial", 16.25F, FontStyle.Bold); g.DrawString("OFFLINE", font, Brushes.White, Rect, stringFormat); } } //画对号 if (Checked) { //g.DrawLine(BorderPen, 10, 10, 20, 20); int x = Rect.Left + Rect.Width - 30; int y = Rect.Top + 8; Pen pen = new Pen(new SolidBrush(Color.DarkOrange), this.BorderThickness); for (int i = 0; i < 6; i++) { g.DrawLine(pen, x, y, x, y + 6); x++; y++; } for (int i = 0; i < 11; i++) { g.DrawLine(pen, x, y, x, y + 6); x++; y--; } if (pen != null) { pen.Dispose(); } } //销毁Graphic 对象 if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderPen.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } }
private void DrawBackground(System.Drawing.Graphics g) { //Graphics g = bg.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; int ArcWidth = this.C_RoundCorners * 2; int ArcHeight = this.C_RoundCorners * 2; int ArcX1 = 0; int ArcX2 = (this.ShadowControl) ? (this.Width - (ArcWidth + 1)) - this.ShadowThickness : this.Width - (ArcWidth + 1); int ArcY1 = 0; int ArcY2 = (this.ShadowControl) ? (this.Height - (ArcHeight + 1)) - this.ShadowThickness : this.Height - (ArcHeight + 1); System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(_colorFrame); //this.BorderColor System.Drawing.Pen BorderPen = new Pen(BorderBrush, _frameBorder); //this.BorderThickness System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = new SolidBrush(this.BackgroundColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //画出阴影效果 if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, SweepAngle); //顶端的左角 ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, SweepAngle); //顶端右角 ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, SweepAngle); //底部右角 ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, SweepAngle); //底部左角 ShadowPath.CloseAllFigures(); g.FillPath(ShadowBrush, ShadowPath); } //画出图形 path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, SweepAngle); path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, SweepAngle); path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, SweepAngle); path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, SweepAngle); path.CloseAllFigures(); if (this.C_BackgroundGradientMode == DutBoxGradientMode.None) { g.FillPath(BackgroundBrush, path); } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); g.FillPath(BackgroundGradientBrush, path); } //画对号 if (IsActivedDut && ManualChecked) { //g.DrawLine(BorderPen, 10, 10, 20, 20); int x = Width - 30; int y = 12; /* * x--; y++; * g.DrawLine(pen, x, y, x, y + 4); * x--; y++; * g.DrawLine(pen, x, y, x, y + 2); * x--; y++; * x = Width - 30; * y = 12; * */ for (int i = 0; i < 6; i++) { g.DrawLine(CheckedPen, x, y, x, y + 6); x++; y++; } for (int i = 0; i < 12; i++) { g.DrawLine(CheckedPen, x, y, x, y + 6); x++; y--; } /* * g.DrawLine(pen, x, y + 2, x, y + 6); * x++; y++; * g.DrawLine(pen, x, y + 2, x, y + 4); * x++; y++; * */ } //画边框 if (IsActivedDut) { g.DrawPath(BorderPen, path); } else { System.Drawing.Brush defaultBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen defaultPen = new Pen(defaultBrush, this.BorderThickness); g.DrawPath(defaultPen, path); } //销毁Graphic 对象 if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderPen.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } }
/// <summary>This method will paint the control.</summary> /// <param name="g">The paint event graphics object.</param> private void PaintBack(System.Drawing.Graphics g) { //Set Graphics smoothing mode to Anit-Alias-- g.SmoothingMode = SmoothingMode.AntiAlias; //------------------------------------------- //Declare Variables------------------ int ArcWidth = this.RoundCorners * 2; int ArcHeight = this.RoundCorners * 2; int ArcX1 = 0; int ArcX2 = (this.ShadowControl) ? (this.Width - (ArcWidth + 1)) - this.ShadowThickness : this.Width - (ArcWidth + 1); int ArcY1 = 10; int ArcY2 = (this.ShadowControl) ? (this.Height - (ArcHeight + 1)) - this.ShadowThickness : this.Height - (ArcHeight + 1); int intXEnd = 20; if (GroupBoxAlignMode.Center == this._vGroupBoxAlignMode) { intXEnd += _vXTrans; } else if (GroupBoxAlignMode.Right == this._vGroupBoxAlignMode) { intXEnd += _vXTrans * 2; } int intTextLength = g.MeasureString(this.GroupTitle, this.Font).ToSize().Width + 34 - (ArcWidth + 1) - 20; int intXStart = intXEnd + intTextLength + ArcWidth; int X1 = intXEnd; int X2 = intXStart; if (this.GroupImage != null) { if (this.ShowTileRectangle) { X2 += 18; } else { X2 += 10; } } else { if (!this.ShowTileRectangle) { X1 += 8 - this.TextLineSpace; X2 -= 8 - this.TextLineSpace; } } X1 -= this.TitleLeftSpace; X2 -= this.TitleLeftSpace; System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = new SolidBrush(this.BackgroundColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //----------------------------------- //Check if shadow is needed---------- if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left ShadowPath.CloseAllFigures(); //Paint Rounded Rectangle------------ g.FillPath(ShadowBrush, ShadowPath); //----------------------------------- } //----------------------------------- //Edit BY WZW 2008-12-16 //Create Rounded Rectangle Path------ //path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left //path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right //path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right //path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left //path.CloseAllFigures(); //g.DrawPath(BorderPen, path); //----------------------------------- //g.DrawArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); //绘制标题外边框----------------------- //左上角 g.DrawArc(BorderPen, ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); //左上至右上分两段画线,两段之间为标题外框 BorderPen = new Pen(BorderBrush, this.BorderThickness); g.DrawLine(BorderPen, new Point(ArcX1 + this.RoundCorners, ArcY1), new Point(X1, ArcY1)); //左边一段直线 BorderPen = new Pen(BorderBrush, this.BorderThickness); g.DrawLine(BorderPen, new Point(X2, ArcY1), new Point(ArcX2 + this.RoundCorners, ArcY1)); //右边一段直线 //右上角 g.DrawArc(BorderPen, ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); if (!_vBorderTopOnly) { //右上至右下 g.DrawLine(BorderPen, new Point(ArcX2 + ArcWidth, ArcY1 + this.RoundCorners), new Point(ArcX2 + ArcHeight, ArcY2 + this.RoundCorners)); //右下角 g.DrawArc(BorderPen, ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //右下至左下 g.DrawLine(BorderPen, new Point(ArcX2 + this.RoundCorners, ArcY2 + ArcWidth), new Point(ArcX1 + this.RoundCorners, ArcY2 + ArcWidth)); //左下角 g.DrawArc(BorderPen, ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //左下只左上 g.DrawLine(BorderPen, new Point(ArcX1, ArcY2 + this.RoundCorners), new Point(ArcX1, ArcY1 + this.RoundCorners)); //g.DrawPath(BorderPen, path); } //Check if Gradient Mode is enabled-- if (this.BackgroundGradientMode == GroupBoxGradientMode.None) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); //Paint Rounded Rectangle------------ g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } //----------------------------------- //Delete BY WZW //Paint Borded----------------------- //g.DrawPath(BorderPen, path); //g.DrawLine(SystemPens.Control, 10, 10, 100, 10); //----------------------------------- //Destroy Graphic Objects------------ if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderBrush.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } //----------------------------------- }
/// <summary>This method will paint the group title.</summary> /// <param name="g">The paint event graphics object.</param> private void PaintGroupText(System.Drawing.Graphics g) { //Check if string has something------------- if (this.GroupTitle == string.Empty) { return; } //------------------------------------------ //Set Graphics smoothing mode to Anit-Alias-- g.SmoothingMode = SmoothingMode.AntiAlias; //------------------------------------------- //Declare Variables------------------ SizeF stringSize = g.MeasureString(this.GroupTitle, this.Font); Size stringSize2 = stringSize.ToSize(); if (this.GroupImage != null) { stringSize2.Width += 18; } //int ArcWidth = this.RoundCorners; //int ArcHeight = this.RoundCorners; int arcWidth = this.HeaderRoundCorners; int arcHeight = this.HeaderRoundCorners; //int intX1 = 0; //int intX2 = 0; //int ArcX1 = 10; //int ArcX2 = (StringSize2.Width + 34) - (ArcWidth + 1); int ArcX1 = 20; int ArcX2 = (stringSize2.Width + 34) - (arcWidth + 1); int ArcY1 = 2; int ArcY2 = 22 - (arcHeight + 1); //Add by WZW 2008-12-16 增加GroupTitleBox对齐方式 ===Start int intMidX = this.Size.Width / 2; int intMidX1 = (ArcX2 - ArcX1) / 2; int CustomStringWidth = (this.GroupImage != null) ? 44 : 28; _vXTrans = intMidX - intMidX1 - ArcX1;//X坐标平移距离 int intTitleTextSpace = CustomStringWidth - ArcX1; //中间对齐 if (this._vGroupBoxAlignMode == GroupBoxAlignMode.Center) { ArcX1 = intMidX - intMidX1; ArcX2 = intMidX + intMidX1; CustomStringWidth = ArcX1 + intTitleTextSpace; } else if (this._vGroupBoxAlignMode == GroupBoxAlignMode.Right) { ArcX1 = intMidX + intMidX - ArcX2; ArcX2 = ArcX1 + intMidX1 + intMidX1; CustomStringWidth = ArcX1 + intTitleTextSpace; } //标题与左边线距离 ArcX1 -= this.TitleLeftSpace; ArcX2 -= this.TitleLeftSpace; //Add by WZW 2008-12-16 增加GroupTitleBox对齐方式 ===End System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor); System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness); System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null; System.Drawing.Brush BackgroundBrush = (this.PaintGroupBox) ? new SolidBrush(this.CustomGroupBoxColor) : new SolidBrush(this.BackgroundColor); System.Drawing.SolidBrush TextColorBrush = new SolidBrush(this.ForeColor); System.Drawing.SolidBrush ShadowBrush = null; System.Drawing.Drawing2D.GraphicsPath ShadowPath = null; //----------------------------------- //Check if shadow is needed---------- if (this.ShadowControl) { ShadowBrush = new SolidBrush(this.ShadowColor); ShadowPath = new System.Drawing.Drawing2D.GraphicsPath(); ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), arcWidth, arcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), arcWidth, arcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), arcWidth, arcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), arcWidth, arcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left ShadowPath.CloseAllFigures(); //Paint Rounded Rectangle------------ g.FillPath(new SolidBrush(Color.Transparent), ShadowPath); //g.FillPath(ShadowBrush, ShadowPath); //----------------------------------- } //----------------------------------- //Edit BY WZW 2008-12-16 //是否显示标题边框------ if (this._vShowTileRectangle) { //创建title边框路径 path.AddArc(ArcX1, ArcY1, arcWidth, arcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left path.AddArc(ArcX2, ArcY1, arcWidth, arcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right path.AddArc(ArcX2, ArcY2, arcWidth, arcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right path.AddArc(ArcX1, ArcY2, arcWidth, arcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left path.CloseAllFigures(); //画Title边框 g.DrawPath(BorderPen, path); } //----------------------------------- //Check if Gradient Mode is enabled-- if (this.PaintGroupBox) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { if (this.BackgroundGradientMode == GroupBoxGradientMode.None) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode); //Paint Rounded Rectangle------------ g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } } //----------------------------------- //绘制title文字------------------------- //int CustomStringWidth = (this.GroupImage != null) ? 44 : 28; //if(this.GroupImage!=null) //{ // CustomStringWidth += 2; //} //g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth, 5); // g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth-this.TitleLeftSpace-2, 5); g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth - this.TitleLeftSpace, 5); //----------------------------------- //Draw GroupImage if there is one---- if (this.GroupImage != null) { //因增加了标题对齐功能,需修改X坐标值 By WZW 2008-12-17 g.DrawImage(this.GroupImage, ArcX1 + 5, 4, 16, 16); } //释放资源------------ if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderBrush.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (TextColorBrush != null) { TextColorBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } }
/// <summary>This method will paint the control.</summary> /// <param name="g">The paint event graphics object.</param> private void PaintBack(Graphics g) { //Set Graphics smoothing mode to Anit-Alias-- g.SmoothingMode = SmoothingMode.AntiAlias; //------------------------------------------- //Declare Variables------------------ var ArcWidth = RoundCorners * 2; var ArcHeight = RoundCorners * 2; var ArcX1 = 0; var ArcX2 = ShadowControl ? Width - (ArcWidth + 1) - ShadowThickness : Width - (ArcWidth + 1); var ArcY1 = 10; var ArcY2 = ShadowControl ? Height - (ArcHeight + 1) - ShadowThickness : Height - (ArcHeight + 1); var path = new GraphicsPath(); Brush BorderBrush = new SolidBrush(BorderColor); var BorderPen = new Pen(BorderBrush, BorderThickness); LinearGradientBrush BackgroundGradientBrush = null; Brush BackgroundBrush = new SolidBrush(BackgroundColor); SolidBrush ShadowBrush = null; GraphicsPath ShadowPath = null; //----------------------------------- //Check if shadow is needed---------- if (ShadowControl) { ShadowBrush = new SolidBrush(ShadowColor); ShadowPath = new GraphicsPath(); ShadowPath.AddArc(ArcX1 + ShadowThickness, ArcY1 + ShadowThickness, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // TopCount Left ShadowPath.AddArc(ArcX2 + ShadowThickness, ArcY1 + ShadowThickness, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //TopCount Right ShadowPath.AddArc(ArcX2 + ShadowThickness, ArcY2 + ShadowThickness, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right ShadowPath.AddArc(ArcX1 + ShadowThickness, ArcY2 + ShadowThickness, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left ShadowPath.CloseAllFigures(); //Paint Rounded Rectangle------------ g.FillPath(ShadowBrush, ShadowPath); //----------------------------------- } //----------------------------------- //Create Rounded Rectangle Path------ path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // TopCount Left path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //TopCount Right path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle); //Bottom Left path.CloseAllFigures(); //----------------------------------- //Check if Gradient Mode is enabled-- if (BackgroundGradientMode == GroupBoxGradientMode.None) { //Paint Rounded Rectangle------------ g.FillPath(BackgroundBrush, path); //----------------------------------- } else { BackgroundGradientBrush = new LinearGradientBrush( new Rectangle(0, 0, Width, Height), BackgroundColor, BackgroundGradientColor, (LinearGradientMode)BackgroundGradientMode); //Paint Rounded Rectangle------------ g.FillPath(BackgroundGradientBrush, path); //----------------------------------- } //----------------------------------- //Paint Borded----------------------- g.DrawPath(BorderPen, path); //----------------------------------- //Destroy Graphic Objects------------ if (path != null) { path.Dispose(); } if (BorderBrush != null) { BorderBrush.Dispose(); } if (BorderPen != null) { BorderPen.Dispose(); } if (BackgroundGradientBrush != null) { BackgroundGradientBrush.Dispose(); } if (BackgroundBrush != null) { BackgroundBrush.Dispose(); } if (ShadowBrush != null) { ShadowBrush.Dispose(); } if (ShadowPath != null) { ShadowPath.Dispose(); } //----------------------------------- }