StrokeColor
内容
[
隐藏
]Shape.StrokeColor property
定义描边的颜色。
public Color StrokeColor { get; set; }
评论
这是一个快捷方式Color
财产。
默认值为 Black。
例子
演示如何用纯色填充形状。
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// 写一些文本,然后用浮动形状覆盖它。
builder.Font.Size = 32;
builder.Writeln("Hello world!");
Shape shape = builder.InsertShape(ShapeType.CloudCallout, RelativeHorizontalPosition.LeftMargin, 25,
RelativeVerticalPosition.TopMargin, 25, 250, 150, WrapType.None);
// 使用“StrokeColor”属性设置形状轮廓的颜色。
shape.StrokeColor = Color.CadetBlue;
// 使用“FillColor”属性设置形状内部区域的颜色。
shape.FillColor = Color.LightBlue;
// “Opacity”属性决定颜色在 0-1 范围内的透明度,
// 1 表示完全不透明,0 表示不可见。
// 默认情况下,形状填充是完全不透明的,因此我们看不到该形状上方的文本。
Assert.AreEqual(1.0d, shape.Fill.Opacity);
// 将形状填充颜色的不透明度设置为较低的值,以便我们可以看到其下方的文本。
shape.Fill.Opacity = 0.3;
doc.Save(ArtifactsDir + "Shape.Fill.docx");
演示如何迭代文档中的所有形状。
public void VisitShapes()
{
Document doc = new Document(MyDir + "Revision shape.docx");
ShapeAppearancePrinter visitor = new ShapeAppearancePrinter();
doc.Accept(visitor);
Console.WriteLine(visitor.GetText());
}
/// <summary>
/// 记录有关所访问形状的外观相关信息。
/// </summary>
private class ShapeAppearancePrinter : DocumentVisitor
{
public ShapeAppearancePrinter()
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = new StringBuilder();
}
/// <summary>
/// 将一行附加到 StringBuilder,并为每个缩进级别添加一个前置制表符。
/// </summary>
private void AppendLine(string text)
{
for (int i = 0; i < mTextIndentLevel; i++) mStringBuilder.Append('\t');
mStringBuilder.AppendLine(text);
}
/// <summary>
/// 返回 StringBuilder 累积的所有文本。
/// </summary>
public string GetText()
{
return $"Shapes visited: {mShapesVisited}\n{mStringBuilder}";
}
/// <summary>
/// 当访问者访问 Shape 节点的开头时调用。
/// </summary>
public override VisitorAction VisitShapeStart(Shape shape)
{
AppendLine($"Shape found: {shape.ShapeType}");
mTextIndentLevel++;
if (shape.HasChart)
AppendLine($"Has chart: {shape.Chart.Title.Text}");
AppendLine($"Extrusion enabled: {shape.ExtrusionEnabled}");
AppendLine($"Shadow enabled: {shape.ShadowEnabled}");
AppendLine($"StoryType: {shape.StoryType}");
if (shape.Stroked)
{
Assert.AreEqual(shape.Stroke.Color, shape.StrokeColor);
AppendLine($"Stroke colors: {shape.Stroke.Color}, {shape.Stroke.Color2}");
AppendLine($"Stroke weight: {shape.StrokeWeight}");
}
if (shape.Filled)
AppendLine($"Filled: {shape.FillColor}");
if (shape.OleFormat != null)
AppendLine($"Ole found of type: {shape.OleFormat.ProgId}");
if (shape.SignatureLine != null)
AppendLine($"Found signature line for: {shape.SignatureLine.Signer}, {shape.SignatureLine.SignerTitle}");
return VisitorAction.Continue;
}
/// <summary>
/// 当访问者访问 Shape 节点的末尾时调用。
/// </summary>
public override VisitorAction VisitShapeEnd(Shape shape)
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine($"End of {shape.ShapeType}");
return VisitorAction.Continue;
}
/// <summary>
/// 当访问者访问 GroupShape 节点的开头时调用。
/// </summary>
public override VisitorAction VisitGroupShapeStart(GroupShape groupShape)
{
AppendLine($"Shape group found: {groupShape.ShapeType}");
mTextIndentLevel++;
return VisitorAction.Continue;
}
/// <summary>
/// 当访问者访问 GroupShape 节点的末尾时调用。
/// </summary>
public override VisitorAction VisitGroupShapeEnd(GroupShape groupShape)
{
mTextIndentLevel--;
AppendLine($"End of {groupShape.ShapeType}");
return VisitorAction.Continue;
}
private int mShapesVisited;
private int mTextIndentLevel;
private readonly StringBuilder mStringBuilder;
}
也可以看看
- class Shape
- 命名空间 Aspose.Words.Drawing
- 部件 Aspose.Words