Created
December 15, 2020 12:25
-
-
Save bjoerntx/50808b3f787fb10bfd01fa070ca77043 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 string CreateStyleFromSelection(this TXTextControl.TextControl textControl) { | |
// get current input position | |
var iParStart = textControl.Paragraphs.GetItem( | |
textControl.InputPosition.TextPosition).Start; | |
textControl.Select(iParStart, 0); | |
// create a new paragraph style based on current formatting | |
TXTextControl.ParagraphStyle parStyle = | |
new TXTextControl.ParagraphStyle("custom_" + Guid.NewGuid().ToString()); | |
// set style | |
parStyle.Baseline = textControl.Selection.Baseline; | |
parStyle.Bold = textControl.Selection.Bold; | |
parStyle.FontName = textControl.Selection.FontName; | |
parStyle.FontSize = textControl.Selection.FontSize; | |
parStyle.ForeColor = textControl.Selection.ForeColor; | |
parStyle.Italic = textControl.Selection.Italic; | |
parStyle.Strikeout = textControl.Selection.Strikeout; | |
parStyle.TextBackColor = textControl.Selection.TextBackColor; | |
parStyle.Underline = textControl.Selection.Underline; | |
// add style to TextControl | |
textControl.ParagraphStyles.Add(parStyle); | |
// return the style name | |
return parStyle.Name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment