我怎样才能在PowerPoint中从C#换一个TextRange的字体颜色? [英] How can I change the font color of a TextRange in PowerPoint from C#?

查看:1201
本文介绍了我怎样才能在PowerPoint中从C#换一个TextRange的字体颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#创建一个PowerPoint演示文稿:

I created a PowerPoint presentation using C#:

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 + "result\\2_example.ppt", 
                       PowerPoint.PpSaveAsFileType.ppSaveAsDefault, 
                       MsoTriState.msoTrue // TODO: что за параметр???
                      );
pptPresentation.Close();

现在,我怎么可以更改字体颜色 objTextRng

Now, how can I change the font color for objTextRng?

推荐答案

下面的代码将字体颜色设置为红色:

The following code will set the font color to red:

objTextRng.Font.Color.RGB = Color.Red.ToArgb();

如果你想指定不同的颜色,你可以用其他的之一的pre-defined 的颜色,或者使用的 Color.FromArgb 方法

If you want to specify a different color, you can use one of the other pre-defined colors, or specify your own RGB values using the Color.FromArgb method.

无论哪种方式,请确保您调用 ToArgb 颜色对象,使用方法。在 RGB 属性要求指定一个RGB颜色值。

Either way, make sure that you call the ToArgb method on the Color object that you use. The RGB property requires that an RGB color value be specified.

这篇关于我怎样才能在PowerPoint中从C#换一个TextRange的字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆