03-01-2019 01:37 PM
I'm trying to run a C# Rich Text Box example from https://docs.microsoft.com/pl-pl/dotnet/framework/wpf/controls/richtextbox-overview. The idea is to inline bold text in the rich text box.
I was able to rewrite all the code in LabVIEW except the last line: this.Content = myStackPanel;
Can I ask for help with reviving this example? How to get rich text box on the LV front panel and how to inline bold text?
C# below
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Documents;
namespace SDKSample
{
public partial class BasicRichTextBoxWithContentExample : Page
{
public BasicRichTextBoxWithContentExample()
{
StackPanel myStackPanel = new StackPanel();
// Create a FlowDocument to contain content for the RichTextBox.
FlowDocument myFlowDoc = new FlowDocument();
// Create a Run of plain text and some bold text.
Run myRun = new Run("This is flow content and you can ");
Bold myBold = new Bold(new Run("edit me!"));
// Create a paragraph and add the Run and Bold to it.
Paragraph myParagraph = new Paragraph();
myParagraph.Inlines.Add(myRun);
myParagraph.Inlines.Add(myBold);
// Add the paragraph to the FlowDocument.
myFlowDoc.Blocks.Add(myParagraph);
RichTextBox myRichTextBox = new RichTextBox();
// Add initial content to the RichTextBox.
myRichTextBox.Document = myFlowDoc;
myStackPanel.Children.Add(myRichTextBox);
this.Content = myStackPanel;
}
}
}
03-01-2019 02:14 PM
Right click the front panel, open the .NET & ActiveX menu, and click the RichTextBox control.
How to use it, I cannot help with that.
03-01-2019 02:34 PM - edited 03-01-2019 02:36 PM
03-01-2019 03:03 PM
@GerdW wrote:
....but it seems rather straight-forward:
...Until you start trying to format a selection of text to have a bold font. ![]()
03-01-2019 03:26 PM - edited 03-01-2019 03:32 PM
@aputman wrote:
@GerdW wrote:
....but it seems rather straight-forward:
...Until you start trying to format a selection of text to have a bold font.
Which wasn’t the OP’s problem. The text line he wanted to translate can’t be directly translated in LabVIEW since the LabVIEW frontpanel is not a Windows control but rather an owner drawn window. Instead you need to use a .Net container to place the control into, so basically the last line and in fact the entire instantiation of the StackPanel object is not needed but instead the container instantiates the Rich Text control automatically and replaces the myRichTextBox = new RichTextBox(); line.
And yes manipulating the text shown in a RichText control is quite a hassle but that is the same in LabVIEW as well as in any other .Net programming language as the object properties and methods stay the same. The main difference is how to get the correct panel container to put the control into.
03-01-2019 04:13 PM
@rolfk wrote:
@aputman wrote:
@GerdW wrote:
....but it seems rather straight-forward:
...Until you start trying to format a selection of text to have a bold font.
Which wasn’t the OP’s problem. The text line he wanted to translate can’t be directly translated in LabVIEW since the LabVIEW frontpanel is not a Windows control but rather an owner drawn window. Instead you need to use a .Net container to place the control into, so basically the last line and in fact the entire instantiation of the StackPanel object is not needed but instead the container instantiates the Rich Text control automatically and replaces the myRichTextBox = new RichTextBox(); line.
And yes manipulating the text shown in a RichText control is quite a hassle but that is the same in LabVIEW as well as in any other .Net programming language as the object properties and methods stay the same. The main difference is how to get the correct panel container to put the control into.
That's fine. I just happened to go off on a rabbit trail of callback VI's for triggered events and none of it seemed straight-forward to me. Even trying to hard-code a line like "This is flow content and you can <bold>edit me</bold>" into a RTB control doesn't seem straight forward.