加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何从C#更改PowerPoint中TextRange的字体颜色?

发布时间:2020-12-15 08:40:17 所属栏目:百科 来源:网络整理
导读:我使用C#创建了一个PowerPoint演示文稿: PowerPoint.Application powerpointApplication;PowerPoint.Presentation pptPresentation;PowerPoint.Slide Slide;// Create an instance of PowerPoint.powerpointApplication = new PowerPoint.ApplicationClass(
我使用C#创建了一个PowerPoint演示文稿:
PowerPoint.Application powerpointApplication;
PowerPoint.Presentation pptPresentation;
PowerPoint.Slide Slide;

// Create an instance of PowerPoint.
powerpointApplication = new PowerPoint.ApplicationClass();

// Create a PowerPoint presentation.
pptPresentation = powerpointApplication.Presentations.Add(
Microsoft.Office.Core.MsoTriState.msoTrue);


// Create empty slide
Slide = pptPresentation.Slides.Add(1,PowerPoint.PpSlideLayout.ppLayoutBlank);

TextRange objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
objTextRng.Text = "Remote sensing calendar 1";
objTextRng.Font.Name = "Comic Sans MS";
objTextRng.Font.Size = 48;
// TODO: change color
// objTextRng.Font.Color 



// Save presentation
pptPresentation.SaveAs( BasePath + "result2_example.ppt",PowerPoint.PpSaveAsFileType.ppSaveAsDefault,MsoTriState.msoTrue // TODO: что за параметр???
                      );
pptPresentation.Close();

现在,我该如何更改objTextRng的字体颜色?

解决方法

以下代码将字体颜色设置为红色:
objTextRng.Font.Color.RGB = Color.Red.ToArgb();

如果要指定其他颜色,可以使用其他pre-defined colors之一,或使用Color.FromArgb method指定自己的RGB值.

无论哪种方式,请确保在您使用的Color对象上调用ToArgb method. RGB属性要求指定RGB颜色值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读