DevExpress Presentation API Library: Set Slide Background
- 5 minutes to read
Important
The DevExpress Presentation API Library is currently available as a Community Technology Preview (CTP). Note that we do not recommend that you integrate pre-release libraries into mission-critical software applications. You can try the library and share your feedback so that we can make necessary adjustments before the official release. To start a conversation, submit a ticket via the DevExpress Support Center — we’d love to hear from you.
DevExpress Presentation API supports various background types and fill patterns. You can apply a background style to an individual slide. You can also use a slide master or slide layout to apply a consistent style to all child slides.
Apply a Background from a Theme
A Theme is a predefined set of color schemes, fonts, and effects.
Note: The current version of the DevExpress Presentation API library does not implement API members that create and configure themes. You can apply background fills from existing themes available in the presentation. You can configure a theme in Microsoft PowerPoint.
Assign a ThemedSlideBackground instance to the SlideBase.Background property to apply a fill from the slide master’s theme to a slide. ThemedSlideBackground
contains the following options:
- ThemedSlideBackground.FillIndex
- Specifies the index of a fill to be applied to slides. Fill indexes can be in the following range: [1..999]. A valid presentation must contain at least three fill elements in the theme (for example, one SolidFill and two GradientFills.
- ThemedSlideBackground.Color
- Specifies the color used to fill the slide background.
The following code snippet applies the second fill from the theme set in the presentation file and specifies the fill color:
using DevExpress.Docs;
using DevExpress.Docs.Presentation;
slide.Background = new ThemedSlideBackground(2) { Color = new OfficeColor(Color.RoyalBlue) };
Configure Custom Background
Assign a CustomSlideBackground instance to the SlideBase.Background property to apply a custom background. CustomSlideBackground
contains the following settings:
- CustomSlideBackground.Fill
- Specifies the background’s fill type.
- CustomSlideBackground.ShadeToTitle
- Specifies whether to add shadow effects around the slide title.
Apply a Solid Fill
Assign a SolidFill to the CustomSlideBackground.Fill property to fill a slide with a solid color. To set a fill color, specify the SolidFill.Color property or use the corresponding SolidFill
constructor:
using DevExpress.Docs.Presentation;
using DevExpress.Drawing;
using System.Drawing;
Slide slide = new Slide(new SlideLayout(layoutType: SlideLayoutType.Blank, name: "slide"));
SolidFill fill = new SolidFill(Color.LightCyan);
slide.Background = new CustomSlideBackground(fill);
Apply a Gradient Fill
Assign a GradientFill to the CustomSlideBackground.Fill property to fill a slide with a color gradient. Use the following properties to configure gradient settings:
- GradientFill.GradientStops
- Provides access to gradient stops.
- GradientFill.GradientType
- Specifies the type of the gradient. Available options include
Circular
,Linear
,Rectangular
,Shape
. - GradientFill.Angle
- Specifies the gradient rotation angle.
- GradientFill.FillRect
- Specifies the gradient fill direction.
- GradientFill.TileRect
- Specifies the rectangular region to which a gradient is applied.
- GradientFill.FlipType
- Specifies how the image is flipped.
- GradientFill.Scaled
- Specifies whether a gradient is scaled.
using DevExpress.Docs.Presentation;
using DevExpress.Drawing;
using System.Drawing;
Slide slide = new Slide(new SlideLayout(layoutType: SlideLayoutType.Blank, name: "slide"));
GradientFill fill = new GradientFill(gradientType: GradientType.Linear);
fill.GradientStops.Add(new GradientStop { Color = new OfficeColor(Color.Cornsilk), Position = 0.1 });
fill.GradientStops.Add(new GradientStop { Color = new OfficeColor(Color.AliceBlue), Position = 0.3 });
fill.GradientStops.Add(new GradientStop { Color = new OfficeColor(Color.RoyalBlue), Position = 0.9 });
slide.Background = new CustomSlideBackground(fill);
Apply a Pattern Fill
Assign a PatternFill to the CustomSlideBackground.Fill property to fill a slide with a pattern. Use the following properties to configure pattern fill settings:
- PatternFill.PatternType
- Specifies a pattern.
- PatternFill.BackgroundColor
- Specifies the pattern background color.
- PatternFill.ForegroundColor
- Specifies the pattern foreground color.
As an alternative to standalone properties, you can use a PatternFill
constructor to set pattern fill settings in parameters:
using DevExpress.Docs.Presentation;
using DevExpress.Drawing;
using System.Drawing;
Slide slide = new Slide(new SlideLayout(layoutType: SlideLayoutType.Blank, name: "slide"));
PatternFill fill = new PatternFill(patternType: FillPatternType.Vertical, Color.White, Color.Lavender);
slide.Background = new CustomSlideBackground(fill);
Apply a Picture Fill
Assign a PictureFill to the CustomSlideBackground.Fill property to fill a slide with a picture. Use the following properties to configure picture fill settings:
- PictureFill.Image
- Specifies the image used to fill the background.
- PictureFill.AlignType
- Specifies the image alignment.
- PictureFill.FillRect
- Specifies the portion of the slide to fill with the image.
- PictureFill.SourceRect
- Specifies the portion of the source image to fill the slide.
- PictureFill.FlipType
- Specifies the flipping mode for the image.
- PictureFill.OffsetX / PictureFill.OffsetY
- Specify the horizontal and vertical offsets of the image relative to its original position.
- PictureFill.ScaleX / PictureFill.ScaleY
- Specify the horizontal and vertical scale factors for the image used to tile the background.
- PictureFill.Stretch
- Specifies whether to stretch the source image.
using DevExpress.Docs.Presentation;
using DevExpress.Drawing;
using System.Drawing;
Slide slide = new Slide(new SlideLayout(layoutType: SlideLayoutType.Blank, name: "slide"));
string imagePath = "D:\\image.png";
Stream stream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
PictureFill fill = new PictureFill(DXImage.FromStream(stream));
fill.Stretch = true;
slide.Background = new CustomSlideBackground(fill);