Rich Text Editor / Document Model / Inlines / Widget Inlines
In This Topic
    Widget Inlines
    In This Topic

    One of the unique features of Nevron Text is that it allows you to embed any widget derived object (button, check box, text box, etc.) inside paragraphs. This allows for the creation of HTML like interfaces that can be printed, exported to PDF, scaled, and serialized (in NTB or NTX formats).

     Creating Widget Inlines

    You insert a widget inside a paragraph block by creating an instance of the NWidgetInline class - the following example shows how to create a paragraph that contains a simple button:

    Creating Widget Inlines
    Copy Code
    // create some dummy content
    NSection section = new NSection();
    
    NParagraph paragraph = new NParagraph();
    section.Blocks.Add(paragraph);
    
    m_RichText.Content.Sections.Clear();
    m_RichText.Content.Sections.Add(section);
    
    NButton button = new NButton("Click me");
    NWidgetInline buttonWidgetInline = new NWidgetInline();
    button.Tag = paragraph;
    button.Click += new Function<NEventArgs>(button_Click);
    buttonWidgetInline.Content = button;
    
    paragraph.Inlines.Add(buttonWidgetInline);
    
    //...
    
    void button_Click(NEventArgs arg)
    {
    NParagraph paragraph = arg.TargetNode.Tag as NParagraph;
    
    paragraph.Inlines.Add(new NTextInline("New text."));
    }
    

    Now when the user clicks the button the paragraph containing it will contain additional text (as the code above intercepts the button Click event). This shows how to create documents that automatically change in response to user actions. The document can be printed, exported and serialized.

    NTB and NTX formats allow for limited widget inline serialization. They will serialize any type of widget and its content, however event handlers and code are not serialized.
     Setting Widget Properties

    The widget content size preferences (min/max width/height, preferred width/height etc. are all regarded during text layout). The following code snippet shows how to create a simple paragraph that contains a password text box and a label next to it showing the password strength.

    You insert a widget inside a paragraph block by creating an instance of the NWidgetInline class - the following example shows how to create a paragraph that contains a simple button:

    Setting Widget Properties
    Copy Code
    // create some dummy content
    NSection section = new NSection();
    
    NParagraph paragraph = new NParagraph();
    section.Blocks.Add(paragraph);
    
    m_RichText.Content.Sections.Clear();
    m_RichText.Content.Sections.Add(section);
    
    NLabel label = new NLabel("");
    
    NTextBox textBox = new NTextBox();
    textBox.Tag = label;
    textBox.PasswordChar = '*';
    textBox.MaxWidth = 200;
    textBox.MinWidth = 100;
    textBox.TextChanged += new Function<NValueChangeEventArgs>(textBox_TextChanged);
    
    paragraph.Inlines.Add(new NWidgetInline(textBox));
    paragraph.Inlines.Add(new NWidgetInline(label));
    
    //...
    
    void textBox_TextChanged(NValueChangeEventArgs arg)
    {
    NTextBox textBox = arg.TargetNode as NTextBox;
    
    string passStrength = "Weak";
    
    if (textBox.Text.Length > 12)
    {
    passStrength = "Strong";
    }
    else if (textBox.Text.Length > 8)
    {
    passStrength = "Medium";
    }
    
    (textBox.Tag as NLabel).Text = passStrength;
    }
    
    See Also