Accept
Inhalt
[
Ausblenden
]GroupShape.Accept method
Nimmt einen Besucher auf.
public override bool Accept(DocumentVisitor visitor)
Parameter | Typ | Beschreibung |
---|---|---|
visitor | DocumentVisitor | Der Besucher, der die Knoten besuchen wird. |
Rückgabewert
Wahr, wenn alle Knoten besucht wurden; falsch, wennDocumentVisitor
hat den Vorgang abgebrochen, bevor alle Knoten besucht wurden.
Bemerkungen
Enumeriert diesen Knoten und alle seine Kinder. Jeder Knoten ruft eine entsprechende Methode aufDocumentVisitor
.
Weitere Informationen finden Sie im Besucher-Entwurfsmuster.
AnrufeVisitGroupShapeStart
, dann ruftAccept
für alle Kindformen dieser Gruppenform und ruftVisitGroupShapeEnd
am Ende.
Beispiele
Zeigt, wie Sie eine Gruppe von Formen erstellen und deren Inhalt mithilfe eines Dokumentbetrachters drucken.
public void GroupOfShapes()
{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Wenn Sie „nicht-primitive“ Formen erstellen müssen, wie z. B. SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
// Eine abgerundete obere Ecke, eine abgeschnittene Ecke, eine abgerundete obere Ecke, abgerundete diagonale Ecke
// Bitte verwenden Sie DocumentBuilder.InsertShape-Methoden.
Shape balloon = new Shape(doc, ShapeType.Balloon)
{
Width = 200,
Height = 200,
Stroke = { Color = Color.Red }
};
Shape cube = new Shape(doc, ShapeType.Cube)
{
Width = 100,
Height = 100,
Stroke = { Color = Color.Blue }
};
GroupShape group = new GroupShape(doc);
group.AppendChild(balloon);
group.AppendChild(cube);
Assert.True(group.IsGroup);
builder.InsertNode(group);
ShapeGroupPrinter printer = new ShapeGroupPrinter();
group.Accept(printer);
Console.WriteLine(printer.GetText());
}
/// <summary>
/// Gibt den Inhalt einer besuchten Formgruppe auf der Konsole aus.
/// </summary>
public class ShapeGroupPrinter : DocumentVisitor
{
public ShapeGroupPrinter()
{
mBuilder = new StringBuilder();
}
public string GetText()
{
return mBuilder.ToString();
}
public override VisitorAction VisitGroupShapeStart(GroupShape groupShape)
{
mBuilder.AppendLine("Shape group started:");
return VisitorAction.Continue;
}
public override VisitorAction VisitGroupShapeEnd(GroupShape groupShape)
{
mBuilder.AppendLine("End of shape group");
return VisitorAction.Continue;
}
public override VisitorAction VisitShapeStart(Shape shape)
{
mBuilder.AppendLine("\tShape - " + shape.ShapeType + ":");
mBuilder.AppendLine("\t\tWidth: " + shape.Width);
mBuilder.AppendLine("\t\tHeight: " + shape.Height);
mBuilder.AppendLine("\t\tStroke color: " + shape.Stroke.Color);
mBuilder.AppendLine("\t\tFill color: " + shape.Fill.ForeColor);
return VisitorAction.Continue;
}
public override VisitorAction VisitShapeEnd(Shape shape)
{
mBuilder.AppendLine("\tEnd of shape");
return VisitorAction.Continue;
}
private readonly StringBuilder mBuilder;
}
Siehe auch
- class DocumentVisitor
- class GroupShape
- namensraum Aspose.Words.Drawing
- Montage Aspose.Words