public void TabStops() { //ExStart //ExFor:TabStop.#ctor //ExFor:TabStop.#ctor(Double) //ExFor:TabStop.#ctor(Double,TabAlignment,TabLeader) //ExFor:TabStop.Equals(TabStop) //ExFor:TabStop.IsClear //ExFor:TabStopCollection //ExFor:TabStopCollection.After(Double) //ExFor:TabStopCollection.Before(Double) //ExFor:TabStopCollection.Count //ExFor:TabStopCollection.Equals(TabStopCollection) //ExFor:TabStopCollection.Equals(Object) //ExFor:TabStopCollection.GetHashCode //ExFor:TabStopCollection.Item(Double) //ExFor:TabStopCollection.Item(Int32) //ExSummary:Shows how to add tab stops to a document. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Access the collection of tab stops and add some tab stops to it TabStopCollection tabStops = builder.ParagraphFormat.TabStops; // 72 points is one "inch" on the Microsoft Word tab stop ruler tabStops.Add(new TabStop(72.0)); tabStops.Add(new TabStop(432.0, TabAlignment.Right, TabLeader.Dashes)); Assert.AreEqual(2, tabStops.Count); Assert.IsFalse(tabStops[0].IsClear); Assert.IsFalse(tabStops[0].Equals(tabStops[1])); builder.Writeln("Start\tTab 1\tTab 2"); // Get the collection of paragraphs that we've created ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs; Assert.AreEqual(2, paragraphs.Count); // Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection Assert.AreEqual(paragraphs[0].ParagraphFormat.TabStops, paragraphs[1].ParagraphFormat.TabStops); Assert.AreNotSame(paragraphs[0].ParagraphFormat.TabStops, paragraphs[1].ParagraphFormat.TabStops); Assert.AreNotEqual(paragraphs[0].ParagraphFormat.TabStops.GetHashCode(), paragraphs[1].ParagraphFormat.TabStops.GetHashCode()); // A TabStopCollection can point us to TabStops before and after certain positions Assert.AreEqual(72.0, tabStops.Before(100.0).Position); Assert.AreEqual(432.0, tabStops.After(100.0).Position); doc.Save(ArtifactsDir + "TabStopCollection.TabStops.docx"); //ExEnd }
public void TabStopCollection() { //ExStart //ExFor:TabStop.#ctor //ExFor:TabStop.#ctor(Double) //ExFor:TabStop.#ctor(Double,TabAlignment,TabLeader) //ExFor:TabStop.Equals(TabStop) //ExFor:TabStop.IsClear //ExFor:TabStopCollection //ExFor:TabStopCollection.After(Double) //ExFor:TabStopCollection.Before(Double) //ExFor:TabStopCollection.Clear //ExFor:TabStopCollection.Count //ExFor:TabStopCollection.Equals(TabStopCollection) //ExFor:TabStopCollection.Equals(Object) //ExFor:TabStopCollection.GetHashCode //ExFor:TabStopCollection.Item(Double) //ExFor:TabStopCollection.Item(Int32) //ExSummary:Shows how to work with a document's collection of tab stops. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Access the collection of tab stops and add some tab stops to it TabStopCollection tabStops = builder.ParagraphFormat.TabStops; // 72 points is one "inch" on the Microsoft Word tab stop ruler tabStops.Add(new TabStop(72)); tabStops.Add(new TabStop(432, TabAlignment.Right, TabLeader.Dashes)); Assert.AreEqual(2, tabStops.Count); Assert.IsFalse(tabStops[0].IsClear); Assert.IsFalse(tabStops[0].Equals(tabStops[1])); // Every "tab" character takes the builder's cursor to the next tab stop builder.Writeln("Start\tTab 1\tTab 2"); // Get the collection of paragraphs that we have created ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs; Assert.AreEqual(2, paragraphs.Count); // Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection Assert.AreEqual(paragraphs[0].ParagraphFormat.TabStops, paragraphs[1].ParagraphFormat.TabStops); Assert.AreNotSame(paragraphs[0].ParagraphFormat.TabStops, paragraphs[1].ParagraphFormat.TabStops); // A TabStopCollection can point us to TabStops before and after certain positions Assert.AreEqual(72.0, tabStops.Before(100.0).Position); Assert.AreEqual(432.0, tabStops.After(100.0).Position); // We can clear a paragraph's TabStopCollection to revert to the default tabbing behaviour paragraphs[1].ParagraphFormat.TabStops.Clear(); Assert.AreEqual(0, paragraphs[1].ParagraphFormat.TabStops.Count); doc.Save(ArtifactsDir + "TabStopCollection.TabStopCollection.docx"); //ExEnd doc = new Document(ArtifactsDir + "TabStopCollection.TabStopCollection.docx"); tabStops = doc.FirstSection.Body.Paragraphs[0].ParagraphFormat.TabStops; Assert.AreEqual(2, tabStops.Count); TestUtil.VerifyTabStop(72.0d, TabAlignment.Left, TabLeader.None, false, tabStops[0]); TestUtil.VerifyTabStop(432.0d, TabAlignment.Right, TabLeader.Dashes, false, tabStops[1]); tabStops = doc.FirstSection.Body.Paragraphs[1].ParagraphFormat.TabStops; Assert.AreEqual(0, tabStops.Count); }