private void PaintBackgroundPart(Graphics g, Rectangle bounds, GraphicsPath path, Color color1, Color color2, eGradientType gradientType, int gradientAngle) { if(color2.IsEmpty) { if(!color1.IsEmpty) { using(SolidBrush brush=new SolidBrush(color1)) g.FillPath(brush,path); } } else if(!m_ColorTable.NodeTopGradientBegin.IsEmpty) { if (gradientType == eGradientType.Linear) { Rectangle rb = bounds; rb.X--; rb.Height++; rb.Width += 2; using (LinearGradientBrush brush = DisplayHelp.CreateLinearGradientBrush(rb, color1, color2, gradientAngle)) { g.FillPath(brush, path); } } else if (gradientType == eGradientType.Radial) { int d = (int)Math.Sqrt(bounds.Width * bounds.Width + bounds.Height * bounds.Height); GraphicsPath fillPath = new GraphicsPath(); fillPath.AddEllipse(bounds.X - (d - bounds.Width), bounds.Y - (d - bounds.Height) / 2, d, d); using (PathGradientBrush brush = new PathGradientBrush(fillPath)) { brush.CenterColor = color1; brush.SurroundColors = new Color[] { color2 }; g.FillPath(brush, path); } fillPath.Dispose(); } } }
public static Brush CreateBrush(Rectangle bounds, BackgroundColorBlendCollection colorBlend, int gradientAngle, eGradientType gradientType) { eBackgroundColorBlendType blendType = colorBlend.GetBlendType(); if (blendType == eBackgroundColorBlendType.Invalid) return null; if (blendType == eBackgroundColorBlendType.SolidColor) { return new SolidBrush(colorBlend[0].Color); } else if (blendType == eBackgroundColorBlendType.Relative) { try { if (gradientType == eGradientType.Linear) { bounds.Inflate(1, 1); LinearGradientBrush brush = DisplayHelp.CreateLinearGradientBrush(bounds, colorBlend[0].Color, colorBlend[colorBlend.Count - 1].Color, gradientAngle); brush.InterpolationColors = colorBlend.GetColorBlend(); return brush; } else if (gradientType == eGradientType.Radial) { int d = (int)Math.Sqrt(bounds.Width * bounds.Width + bounds.Height * bounds.Height) + 4; GraphicsPath fillPath = new GraphicsPath(); fillPath.AddEllipse(bounds.X - (d - bounds.Width) / 2, bounds.Y - (d - bounds.Height) / 2, d, d); PathGradientBrush brush = new PathGradientBrush(fillPath); brush.CenterColor = colorBlend[0].Color; brush.SurroundColors = new Color[] { colorBlend[colorBlend.Count - 1].Color }; brush.InterpolationColors = colorBlend.GetColorBlend(); return brush; } } catch { return null; } } else { BackgroundColorBlendCollection bc = colorBlend; for (int i = 0; i < bc.Count; i += 2) { BackgroundColorBlend b1 = bc[i]; BackgroundColorBlend b2 = null; if (i < bc.Count) b2 = bc[i + 1]; if (b1 != null && b2 != null) { Rectangle rb = new Rectangle(bounds.X, bounds.Y + (int)b1.Position, bounds.Width, (b2.Position == 1f ? bounds.Height : (int)b2.Position) - (int)b1.Position); return DisplayHelp.CreateLinearGradientBrush(rb, b1.Color, b2.Color, gradientAngle); } } } return null; }
/// <summary> /// Reset all style properties to default values. /// </summary> public void Reset() { m_BackColor=Color.Empty; m_BackColorSchemePart=eColorSchemePart.None; m_BackColor2=Color.Empty; m_BackColor2SchemePart=eColorSchemePart.None; m_BackColorGradientAngle=0; m_BackColorGradientType = eGradientType.Linear; m_BackgroundImage=null; m_BackgroundImagePosition=eStyleBackgroundImage.Stretch; m_BackgroundImageAlpha=255; m_BackColorBlend.Clear(); // Font m_Font=null; // Text Formating m_WordWrap=false; m_TextAlignment=eStyleTextAlignment.Near; m_TextLineAlignment=eStyleTextAlignment.Center; m_TextTrimming=eStyleTextTrimming.EllipsisCharacter; m_TextColor=Color.Empty; m_TextColorSchemePart=eColorSchemePart.None; m_TextShadowColor = Color.Empty; m_TextShadowColorSchemePart = eColorSchemePart.None; m_TextShadowOffset = Point.Empty; // Style margins m_MarginLeft=0; m_MarginRight=0; m_MarginTop=0; m_MarginBottom=0; // Style inside padding m_PaddingLeft=0; m_PaddingRight=0; m_PaddingTop=0; m_PaddingBottom=0; // Border m_BorderLeft=eStyleBorderType.None; m_BorderRight=eStyleBorderType.None; m_BorderTop=eStyleBorderType.None; m_BorderBottom=eStyleBorderType.None; m_BorderColor=Color.Empty; m_BorderColorSchemePart=eColorSchemePart.None; m_BorderColor2 = Color.Empty; m_BorderColor2SchemePart = eColorSchemePart.None; m_BorderGradientAngle = 90; m_BorderColorLight = Color.Empty; m_BorderColorLightSchemePart = eColorSchemePart.None; m_BorderColorLight2 = Color.Empty; m_BorderColorLight2SchemePart = eColorSchemePart.None; m_BorderLightGradientAngle = 90; m_BorderLeftColor=Color.Empty; m_BorderLeftColorSchemePart=eColorSchemePart.None; m_BorderRightColor=Color.Empty; m_BorderRightColorSchemePart=eColorSchemePart.None; m_BorderTopColor=Color.Empty; m_BorderTopColorSchemePart=eColorSchemePart.None; m_BorderBottomColor=Color.Empty; m_BorderBottomColorSchemePart=eColorSchemePart.None; m_BorderLeftWidth=0; m_BorderRightWidth=0; m_BorderTopWidth=0; m_BorderBottomWidth=0; m_CornerType=eCornerType.Square; m_CornerTypeTopLeft=eCornerType.Inherit; m_CornerTypeTopRight=eCornerType.Inherit; m_CornerTypeBottomLeft=eCornerType.Inherit; m_CornerTypeBottomRight=eCornerType.Inherit; m_CornerDiameter=DEFAULT_CORNER_DIAMETER; m_Class = ""; m_MaximumHeight=0; }