Back to Devexpress

How to: Change a Shape's Fill and Outline Color

wpf-400359-controls-and-libraries-spreadsheet-examples-shapes-how-to-change-shape-fill-and-outline-color.md

latest3.6 KB
Original Source

How to: Change a Shape's Fill and Outline Color

  • Jun 07, 2019
  • 2 minutes to read

This example describes how to change a shape’s fill and outline color.

The table below lists an API used to change the shape’s fill and outline settings.

MemberDescription
ShapeFormatBase.FillProvides access to the ShapeFill object containing fill options.
ShapeFormatBase.OutlineProvides access to the ShapeOutline object containing outline options.
ShapeOutline.WidthDefines the outline thickness.
ShapeOutlineFill.SetSolidFillFills a shape or its outline with a solid color.
ShapeOutlineFill.SetGradientFillApplies the gradient effect to the shape’s background or outline.
ShapeFill.SetPatternFillFills the drawing object background or its elements with a repeated pattern.
ShapeFill.SetPictureFillApplies the picture fill to the shape’s background.
ShapeOutlineFill.SetNoFillMakes an element transparent.

The following code sample changes the shapes’ color options to look as they do on the image below.

csharp
// Apply a pattern fill to a frame. 
shape.Fill.SetPatternFill(Color.DarkRed, Color.IndianRed, ShapeFillPatternType.Wave);
// Color the outline black. 
shape.Outline.SetSolidFill(Color.Black);

// Apply a gradient fill to a pentagon. 
shape2.Fill.SetGradientFill(ShapeGradientType.Shape, Color.MediumVioletRed, Color.PaleVioletRed);
// Make the outline transparent. 
shape2.Outline.SetNoFill();

// Apply a solid fill to a text box. 
shape3.Fill.SetSolidFill(Color.Crimson);
// Change the outline width:  
shape3.Outline.Width = 3;

// Add a picture to the explosion's background.  
shape4.Fill.SetPictureFill(SpreadsheetImageSource.FromFile("Documents//condiments.png"));
// Apply a gradient fill to an outline. 
shape4.Outline.SetGradientFill(ShapeGradientType.Linear, Color.PeachPuff, Color.Peru);
vb
' Apply a pattern fill to a frame. 
shape.Fill.SetPatternFill(Color.DarkRed, Color.IndianRed, ShapeFillPatternType.Wave)
' Color the outline black. 
shape.Outline.SetSolidFill(Color.Black)

' Apply a gradient fill to a pentagon. 
shape2.Fill.SetGradientFill(ShapeGradientType.Shape, Color.MediumVioletRed, Color.PaleVioletRed)
' Make the outline transparent. 
shape2.Outline.SetNoFill()

' Apply a solid fill to a text box. 
shape3.Fill.SetSolidFill(Color.Crimson)
' Change the outline width.  
shape3.Outline.Width = 3

' Add a picture to the explosion's background.  
shape4.Fill.SetPictureFill(SpreadsheetImageSource.FromFile("Documents//condiments.png"))
' Apply a gradient fill to an outline. 
shape4.Outline.SetGradientFill(ShapeGradientType.Linear, Color.PeachPuff, Color.Peru)