Created
November 21, 2023 11:18
-
-
Save bjoerntx/2a34577e61df727861b0bfa882abe2ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[HttpPost] | |
public HttpResponseMessage DoComplexFormatting(string ConnectionID) | |
{ | |
// connect the WebSocketHandler with the ConnectionID | |
WebSocketHandler wsHandler = WebSocketHandler.GetInstance(ConnectionID); | |
byte[] data; | |
// save the current selection to a byte array | |
wsHandler.Selection.Save(out data, BinaryStreamType.InternalUnicodeFormat); | |
// load the byte array into a ServerTextControl | |
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) | |
{ | |
tx.Create(); | |
tx.Load(data, TXTextControl.BinaryStreamType.InternalUnicodeFormat); | |
// loop through all words and format the word "TextControl" | |
for (int i = 0; i < tx.Text.Length; i++) | |
{ | |
tx.Select(i, 1); | |
tx.SelectWord(); | |
if (tx.Selection.Text == "TextControl") | |
{ | |
tx.Selection.Bold = true; | |
tx.Selection.Italic = true; | |
tx.Selection.ForeColor = Color.Red; | |
i += tx.Selection.Text.Length; | |
} | |
} | |
// save the document to a byte array and load it into the WebSocketHandler | |
tx.Save(out data, TXTextControl.BinaryStreamType.InternalUnicodeFormat); | |
wsHandler.Selection.Load(data, BinaryStreamType.InternalUnicodeFormat); | |
} | |
return new HttpResponseMessage() | |
{ | |
StatusCode = HttpStatusCode.OK | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment