Search code examples
c#chartspowerpointoffice-interoppowerpoint-interop

How to fill the chart title with a custom gradient background using Microsoft.Office.Interop.PowerPoint?


I have a PowerPoint chart and I want to fill the chart title area with a custom gradient background.

This is the code I tried:

Chart chart = myShape.Chart;
chart.ChartTitle.Fill.TwoColorGradient(MsoGradientStyle.msoGradientHorizontal, 1);
chart.ChartTitle.Fill.ForeColor.RGB = Color.Red.ToArgb();
chart.ChartTitle.Fill.BackColor.RGB = Color.Blue.ToArgb();

Unfortunately, the RGB properties of both ForeColor and BackColor are readonly. So I can't use the code above. I manage to get a Solid custom background using the Interior properety of the ChartTitle, like this:

chart.ChartTitle.Interior.Color = Color.Red;

But I can't find a way to add a gradient background using my custom colors. I also can't find an option to get or set the Gradient Stops.

How can I achieve it using Microsoft.Office.Interop.PowerPoint?


Solution

  • I solved it by using ChartTitle.Format.Fill instead of ChartTitle.Fill.

    chart.ChartTitle.Format.Fill.TwoColorGradient(MsoGradientStyle.msoGradientHorizontal, 1);
    chart.ChartTitle.Format.Fill.ForeColor.RGB = Color.Red.ToArgb();
    chart.ChartTitle.Format.Fill.BackColor.RGB = Color.Blue.ToArgb();