如何使用Microsoft.Office.Interop.PowerPoint向图表元素添加自定义阴影?

时间:2019-12-06 10:53:09

标签: c# vsto office-interop powerpoint-addins powerpoint-interop

我正在尝试向图表的某些元素(例如数据序列点)添加自定义阴影效果。

我设法使用以下代码添加了阴影效果:

var format = myChart.SeriesCollection().Item(1).Points(1).Format;
format.Shadow.Type = MsoShadowType.msoShadow25;

它运行得很好,尽管理解和映射每个阴影类型并不直观。之后,我尝试使用自定义颜色,模糊,大小,透明度,角度和距离自定义此阴影。因此,我使用了以下代码:

try { format.Shadow.ForeColor.RGB = Color.Red.ToArgb(); }   // I know I should convert to BGR format
catch (Exception ex) { Console.WriteLine(ex.ToString()); }  // However, it always throws an exception

try { format.Shadow.Blur = 9.0f; } 
catch (Exception ex) { Console.WriteLine(ex.ToString()); }  // Always an exception is thrown

try { format.Shadow.Size= 25.0f; } 
catch (Exception ex) { Console.WriteLine(ex.ToString()); }  // Always an exception is thrown

try { format.Shadow.Transparency = 0.3f; } 
catch (Exception ex) { Console.WriteLine(ex.ToString()); }  // Always an exception is thrown

不幸的是,对于每个属性,我都会收到以下异常:

  

“ System.InvalidCastException:指定的转换无效。”

为什么会出现此异常?另外,如何设置角度和距离?我应该使用OffsetX和OffsetY吗?

我还尝试查看this question中的自定义原色,但仍然遇到相同的异常。

如何在图表中自定义阴影?

任何帮助将不胜感激。

0 个答案:

没有答案