Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created December 15, 2020 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/d95672e62e789e296eb58301b5ed2b5d to your computer and use it in GitHub Desktop.
Save bjoerntx/d95672e62e789e296eb58301b5ed2b5d to your computer and use it in GitHub Desktop.
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