Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created November 21, 2023 11:18
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/2a34577e61df727861b0bfa882abe2ea to your computer and use it in GitHub Desktop.
Save bjoerntx/2a34577e61df727861b0bfa882abe2ea to your computer and use it in GitHub Desktop.
[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