LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rich Text Box Example

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;
            
        }
    }
}

 

 

Michał Bieńkowski
CLA, CTA, CPI

  1. Did someone devote their time to help solve your problem? Appreciate it and give kudos.
  2. Problem solved? Accept as a solution so that others can find it faster in the future.
  3. Contribute to the development of TestStand by voting on the TestStand Idea Exchange.
0 Kudos
Message 1 of 6
(7,090 Views)

Right click the front panel, open the .NET & ActiveX menu, and click the RichTextBox control.

How to use it, I cannot help with that.

aputman
0 Kudos
Message 2 of 6
(7,067 Views)

Hi bienieck,

 

I never used RTB before, but it seems rather straight-forward:

check.png

I just placed a .NET container on the frontpanel and selected the RTB. Then added some property nodes in the block diagram…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 6
(7,058 Views)

@GerdW wrote:

....but it seems rather straight-forward:


...Until you start trying to format a selection of text to have a bold font.  Smiley Wink

aputman
0 Kudos
Message 4 of 6
(7,044 Views)

@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.  Smiley Wink


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.

 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 5 of 6
(7,040 Views)

@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.  Smiley Wink


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. 

aputman
0 Kudos
Message 6 of 6
(7,022 Views)