C#/VB.NET: Set Background Color or Picture for PowerPoint Slides

Setting a background for slides is a crucial step in creating a visually appealing and impactful presentation. A well-designed background can provide a consistent visual theme, drawing your audience's attention and keeping them engaged throughout your presentation. In this article, we will demonstrate how to set background color or picture for PowerPoint slides in C# and VB.NET using Spire.Presentation for .NET library.

Install Spire.Presentation for .NET

To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Presentation

Set a Background Color for a PowerPoint Slide in C# and VB.NET

Adding a background color for a PowerPoint slide is very simple. You just need to set the fill mode of the slide’s background as a solid fill and then set a color for the slide’s background. The detailed steps are as follows:

  • Initialize an instance of the Presentation class.
  • Load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Get a specific slide using Presentation.Slides[int index] property.
  • Access the background of the slide using ISlide.SlideBackground property.
  • Set the type of the slide's background as a custom type using SlideBackground.Type property.
  • Set the fill mode of the slide’s background as a solid fill using SlideBackground.Fill.FillType property.
  • Set a color for the slide’s background using SlideBackground.Fill.SolidColor.Color property.
  • Save the result presentation using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace SolidBackground
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Presentation class
            Presentation ppt = new Presentation();
            //Load a PowerPoint presentation
            ppt.LoadFromFile("Sample.pptx");

            //Get the first slide
            ISlide slide = ppt.Slides[0];

            //Access the background of the slide
            SlideBackground background = slide.SlideBackground;

            //Set the type of the slide's background as a custom type
            background.Type = BackgroundType.Custom;
            //Set the fill mode of the slide's background as a solid fill
            background.Fill.FillType = FillFormatType.Solid;
            //Set a color for the slide's background
            background.Fill.SolidColor.Color = Color.PaleTurquoise;

            //Save the result presentation
            ppt.SaveToFile("Solidbackground.pptx", FileFormat.Pptx2013);
            ppt.Dispose();
        }
    }
}

C#/VB.NET: Set Background Color or Picture for PowerPoint Slides

Set a Gradient Background for a PowerPoint Slide in C# and VB.NET

Adding a gradient background is a little complex. You need to set the fill mode of the slide’s background as a gradient fill and then set the gradient stops and colors. The detailed steps are as follows:

  • Initialize an instance of the Presentation class.
  • Load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Get a specific slide using Presentation.Slides[int index] property.
  • Access the background of the slide using ISlide.SlideBackground property.
  • Set the type of the slide's background as a custom type using SlideBackground.Type property.
  • Set the fill mode of the slide’s background as a gradient fill using SlideBackground.Fill.FillType property.
  • Set gradient stops and colors for the slide’s background using SlideBackground.Fill.Gradient.GradientStops.Append() method.
  • Set the shape type and angle for the gradient fill.
  • Save the result presentation using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace GradientBackground
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Presentation class
            Presentation ppt = new Presentation();
            //Load a PowerPoint presentation
            ppt.LoadFromFile("Sample.pptx");

            //Get the first slide
            ISlide slide = ppt.Slides[0];

            //Access the background of the slide
            SlideBackground background = slide.SlideBackground;

            //Set the type of the slide's background as a custom type
            background.Type = BackgroundType.Custom;
            //Set the fill mode of the slide's background as a gradient fill
            background.Fill.FillType = FillFormatType.Gradient;

            //Set gradient stops and colors
            background.Fill.Gradient.GradientStops.Append(0.1f, Color.LightCyan);
            background.Fill.Gradient.GradientStops.Append(0.7f, Color.LightSeaGreen);

            //Set the shape type of the gradient fill
            background.Fill.Gradient.GradientShape = GradientShapeType.Linear;
            //Set the angle of the gradient fill
            background.Fill.Gradient.LinearGradientFill.Angle = 45;

            //Save the result presentation
            ppt.SaveToFile("Gradientbackground.pptx", FileFormat.Pptx2013);
            ppt.Dispose();
        }
    }
}

C#/VB.NET: Set Background Color or Picture for PowerPoint Slides

Set a Background Picture for a PowerPoint Slide in C# and VB.NET

To add a background picture for a PowerPoint slide, you need to set the fill mode of the slide’s background as a picture fill, then add a picture to the image collection of the presentation and set it as the slide’s background. The detailed steps are as follows:

  • Initialize an instance of the Presentation class.
  • Load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Get a specific slide using Presentation.Slides[int index] property.
  • Access the background of the slide using ISlide.SlideBackground property.
  • Set the type of the slide's background as a custom type using SlideBackground.Type property.
  • Set the fill mode of the slide’s background as a picture fill using SlideBackground.Fill.FillType property.
  • Add an image to the image collection of the presentation using Presentation.Images.Append() method.
  • Set the image as the slide’s background using background.Fill.PictureFill.Picture.EmbedImage property.
  • Save the result presentation using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace PictureBackground
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Presentation class
            Presentation ppt = new Presentation();
            //Load a PowerPoint presentation
            ppt.LoadFromFile("Sample.pptx");

            //Get the first slide
            ISlide slide = ppt.Slides[0];

            //Access the background of the slide
            SlideBackground background = slide.SlideBackground;

            //Set the type of the slide's background as a custom type
            background.Type = BackgroundType.Custom;
            //Set the fill mode of the slide's background as a picture fill
            background.Fill.FillType = FillFormatType.Picture;

            Image img = Image.FromFile("bg.jpg");
            //Add an image to the image collection of the presentation
            IImageData image = ppt.Images.Append(img);
            //Set the image as the slide's background
            background.Fill.PictureFill.FillType = PictureFillType.Stretch;
            background.Fill.PictureFill.Picture.EmbedImage = image;

            //Save the result presentation
            ppt.SaveToFile("Picturebackground.pptx", FileFormat.Pptx2013);
            ppt.Dispose();
        }
    }
}

C#/VB.NET: Set Background Color or Picture for PowerPoint Slides

Set a Background for a Slide Master in PowerPoint in C# and VB.NET

If you don’t wish to set backgrounds for slides one by one, you can set a background for the slide master, then all slides using the same slide master will be applied with the background automatically. The following steps show how to set a solid background color for a slide master:

  • Initialize an instance of the Presentation class.
  • Load a PowerPoint presentation using Presentation.LoadFromFile() method.
  • Get a specific slide master using Presentation.Masters[int index] property.
  • Access the background of the slide using ISlide.SlideBackground property.
  • Set the type of the slide's background as a custom type using SlideBackground.Type property.
  • Set the fill mode of the slide’s background as a solid fill using SlideBackground.Fill.FillType property.
  • Set a color for the slide’s background using SlideBackground.Fill.SolidColor.Color property.
  • Save the result presentation using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace AddBackgroundToSlideMaster
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Presentation class
            Presentation ppt = new Presentation();
            //Load a PowerPoint presentation
            ppt.LoadFromFile("Sample.pptx");

            //Get the first slide master
            IMasterSlide slide = ppt.Masters[0];

            //Access the background of the slide
            SlideBackground background = slide.SlideBackground;

            //Set the type of the slide's background as a custom type
            background.Type = BackgroundType.Custom;
            //Set the fill mode of the slide's background as a solid fill
            background.Fill.FillType = FillFormatType.Solid;
            //Set a color for the slide's background
            background.Fill.SolidColor.Color = Color.PeachPuff;

            //Save the result presentation
            ppt.SaveToFile("AddBackgroundToSlideMaster.pptx", FileFormat.Pptx2013);
            ppt.Dispose();

        }
    }
}

C#/VB.NET: Set Background Color or Picture for PowerPoint Slides

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.