Shading

Shading class

包含对象的阴影属性。

要了解更多信息,请访问使用文档进行编程文档文章。

public class Shading : InternableComplexAttr

特性

姓名描述
BackgroundPatternColor { get; set; }获取或设置应用于背景的颜色Shading对象.
BackgroundPatternThemeColor { get; set; }获取或设置与此关联的应用配色方案中的背景图案主题颜色Shading对象.
BackgroundTintAndShade { get; set; }获取或设置使背景主题颜色变亮或变暗的双精度值。
ForegroundPatternColor { get; set; }获取或设置应用于前景的颜色Shading对象.
ForegroundPatternThemeColor { get; set; }获取或设置与此关联的应用配色方案中的前景色图案主题颜色Shading对象.
ForegroundTintAndShade { get; set; }获取或设置使前景主题颜色变亮或变暗的双精度值。
Texture { get; set; }获取或设置阴影纹理。

方法

姓名描述
ClearFormatting()从对象中移除阴影。
override Equals(object)确定指定对象的值是否等于当前对象。
Equals(Shading)确定指定的Shading价值与当前Shading.
override GetHashCode()用作此类型的哈希函数。

例子

展示如何使用边框和阴影装饰文本。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

BorderCollection borders = builder.ParagraphFormat.Borders;
borders.DistanceFromText = 20;
borders[BorderType.Left].LineStyle = LineStyle.Double;
borders[BorderType.Right].LineStyle = LineStyle.Double;
borders[BorderType.Top].LineStyle = LineStyle.Double;
borders[BorderType.Bottom].LineStyle = LineStyle.Double;

Shading shading = builder.ParagraphFormat.Shading;
shading.Texture = TextureIndex.TextureDiagonalCross;
shading.BackgroundPatternColor = Color.LightCoral;
shading.ForegroundPatternColor = Color.LightSalmon;

builder.Write("This paragraph is formatted with a double border and shading.");
doc.Save(ArtifactsDir + "DocumentBuilder.ApplyBordersAndShading.docx");

展示如何在构建表格时应用边框和阴影颜色。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// 启动一个表格并设置其边框的默认颜色/粗细。
Table table = builder.StartTable();
table.SetBorders(LineStyle.Single, 2.0, Color.Black);

// 创建一行包含两个具有不同背景颜色的单元格。
builder.InsertCell();
builder.CellFormat.Shading.BackgroundPatternColor = Color.LightSkyBlue;
builder.Writeln("Row 1, Cell 1.");
builder.InsertCell();
builder.CellFormat.Shading.BackgroundPatternColor = Color.Orange;
builder.Writeln("Row 1, Cell 2.");
builder.EndRow();

// 重置单元格格式以禁用背景颜色
// 为构建器创建的所有新单元格设置自定义边框粗细,
// 然后构建第二行。
builder.CellFormat.ClearFormatting();
builder.CellFormat.Borders.Left.LineWidth = 4.0;
builder.CellFormat.Borders.Right.LineWidth = 4.0;
builder.CellFormat.Borders.Top.LineWidth = 4.0;
builder.CellFormat.Borders.Bottom.LineWidth = 4.0;

builder.InsertCell();
builder.Writeln("Row 2, Cell 1.");
builder.InsertCell();
builder.Writeln("Row 2, Cell 2.");

doc.Save(ArtifactsDir + "DocumentBuilder.TableBordersAndShading.docx");

也可以看看