Created
December 15, 2020 12:27
-
-
Save bjoerntx/d95672e62e789e296eb58301b5ed2b5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void CompareAndApplyStyle( | |
this TXTextControl.TextControl textControl, | |
string paragraphStyleName) { | |
// store input position | |
var iStartPos = textControl.Selection.Start; | |
// retrieve the style based on a name | |
TXTextControl.ParagraphStyle style = | |
textControl.ParagraphStyles.GetItem(paragraphStyleName); | |
// loop through all paragraphs to check whether the style | |
// matches the paragraph style | |
foreach (TXTextControl.Paragraph par in textControl.Paragraphs) { | |
textControl.Select(par.Start, 0); | |
var selection = textControl.Selection; | |
if (selection.Baseline == style.Baseline && | |
selection.Bold == style.Bold && | |
selection.FontName == style.FontName && | |
selection.FontSize == style.FontSize && | |
selection.ForeColor == style.ForeColor && | |
selection.Italic == style.Italic && | |
selection.Strikeout == style.Strikeout && | |
selection.Underline == style.Underline) { | |
// style matches - apply style | |
par.FormattingStyle = paragraphStyleName; | |
} | |
} | |
// reset input position | |
textControl.Selection.Start = iStartPos; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment