Hi I'm looking for any idea to make something like that:
Some Text---------------------------------------------------
This "------" I have to make on button click to the end of line.
My idea was to make it on tabstop with dashed leader, but it make problem because when im trying to use ^t inside text after this it makes dashes also. It can't be done just by typing dashes because second button would be to clear that dashing from whole document.
This is code that I make but like I said it is not good because that ^t at any other place of document is terrible
public void DashingSingleLane()
{
Word.Range rng = Globals.ThisAddIn.Application.Selection.Range;
if (rng.Start == rng.End)
{
float pageWidth = classDocument.PageSetup.PageWidth - classDocument.PageSetup.LeftMargin - classDocument.PageSetup.RightMargin;
foreach (Word.Paragraph singleParagraph in rng.Paragraphs)
{
if ((singleParagraph.Range.Text != "\r") && (singleParagraph.Range.Text.IndexOf("\t") == -1))
{
singleParagraph.TabStops.Add(pageWidth, Word.WdTabAlignment.wdAlignTabRight, Word.WdTabLeader.wdTabLeaderDashes);
Globals.ThisAddIn.Application.Selection.EndKey(Microsoft.Office.Interop.Word.WdUnits.wdLine);
Globals.ThisAddIn.Application.Selection.TypeText("\t");
}
}
}
}
I found that to make it good I need also to put Tabstop with left align exacly at the end of sentence. Something like that
singleParagraph.TabStops.AddPosition_in_Point, Word.WdTabAlignment.wdAlignTabLeft, Word.WdTabLeader.wdTabLeaderDashes);
But I don't know how to get that position in point
I'm thinking about that problem from 2 days and I don't have any good idea. I hope somebody would have some good think.
In order to determine the horizontal position of the current selection (or a Range) you can use the Information property. This takes a member of the WdInformation enumeration that tells Word what value to return.
You can return the information as a value from the left side of the page wdHorizontalPositionRelativeToPage
, or from the "text boundary", which would be the margin in "plain text" (as opposed to a table or some other construct) on a page with a single column - wdHorizontalPositionRelativeToTextBoundary
.
So, for example:
//Position is returned in POINTS, which is what TabStop uses
float selPosition = Selection.get_Information(Word.WdInformation.wdHorizontalPositionRelativeToTextBoundary);
singleParagraph.TabStops.Add(selPosition, Word.WdTabAlignment.wdAlignTabRight, Word.WdTabLeader.wdTabLeaderDashes);