Nevron .NET Vision

In This Topic
    Using the NTextDocument object
    In This Topic

    Overview

    The NRichTextLabel component may be configured by providing setting the Document property directly. You may apply styles in much the same manner as in HTML and CSS. Styles are composable and inheritable per any dom element. You may take full advantage of the Nevron core graphics device and rendering capabilities like shadows, fill styles, stroke styles, image filters like in Photoshop, etc.

     

    Creating And Populating a NTextDocument

    The following code demonstrates how to create a four-paragraph bulleted list, each paragraph containing 4 formatted string fragments formatted using different styles:

     

    [C#]
    
    NTextDocument document = new NTextDocument();
    NStyle style;
    
    // create a bullet list style with upper roman bullets
    NListStyleElement listStyleElement = new NListStyleElement();
    
    //create four paragraphs with different alignments
    NParagraphElement paragraph;
    NStringFragment stringFragment;
    NImageFilter imgFilter;
    NImageFiltersStyle filters;
    
    foreach(ParagraphAlignment pAlign in Enum.GetValues(typeof(ParagraphAlignment)))
    {
            paragraph = new NParagraphElement();
    
            style = new NStyle();
            style.ParagraphAlignment = pAlign;
            paragraph.Style = style;
    
            style = new NStyle();
            style.FontName = "Trebuchet MS";
            style.FontStyleEx = FontStyleEx.Bold;
            style.FontSize = new NLength(12);
            style.ShadowStyle = new NShadowStyle(ShadowType.LinearBlur, Color.Gray, new NPointL(2, 2));
    
            stringFragment = new NStringFragment("This is \"" + pAlign.ToString() + "\" aligned paragraph.");
            stringFragment.Style = style;
            paragraph.AddChild(stringFragment);
            paragraph.AddChild(new NNewLineFragment());
    
            style = new NStyle();
            style.FontName = "Tahoma";
            style.FontSize = new NLength(9);
            style.FontStyleEx = FontStyleEx.Italic | FontStyleEx.Underline;
            style.FillStyle = new NGradientFillStyle(Nevron.GraphicsCore.GradientStyle.Horizontal, GradientVariant.Variant1, Color.Orange, Color.Black);
            stringFragment = new NStringFragment("Check out the full control over appearance.");
            stringFragment.Style = style;
            paragraph.AddChild(stringFragment);
            paragraph.AddChild(new NNewLineFragment());
    
            style = new NStyle();
            style.FontName = "Verdana";
            style.FontSize = new NLength(10);
            style.FontStyleEx = FontStyleEx.Italic | FontStyleEx.Bold;
            style.FillStyle = new NAdvancedGradientFillStyle(AdvancedGradientScheme.CalmWater1, 1);
            stringFragment = new NStringFragment("You may apply styles per any basis!");
            stringFragment.Style = style;
            paragraph.AddChild(stringFragment);
            paragraph.AddChild(new NNewLineFragment());
    
            style = new NStyle();
            style.FontName = "Arial";
            style.FontSize = new NLength(20);
            style.FontStyleEx = FontStyleEx.Bold;
            style.FillStyle = new NAdvancedGradientFillStyle(AdvancedGradientScheme.Fog1, 0);
    
            //create some image filters
            filters = new NImageFiltersStyle();
            imgFilter = new NBevelAndEmbossImageFilter();
            filters.Filters.Add(imgFilter);
            imgFilter = new NLightingImageFilter();
            filters.Filters.Add(imgFilter);
            style.FillStyle.ImageFiltersStyle = filters;
            
            stringFragment = new NStringFragment("And even image filters!");
            stringFragment.Style = style;
            paragraph.AddChild(stringFragment);
    
            listStyleElement.AddChild(paragraph);
    }
    
    style = new NStyle();
    NTextListStyle textListStyle = new NTextListStyle(TextListStyleType.UpperRoman);
    textListStyle.FillStyle = new NColorFillStyle(Color.Red);
    style.ListStyle = textListStyle;
    style.TopSpacing = new NLength(0);
    listStyleElement.Style = style;
    
    document.AddChild(listStyleElement);
    
    //assign the newly created document to an existing NRichTextLabel instance
    nRichTextLabel1.Document = document;
    

     

    See Also

    Fill Styles | Image Filters | Shadow Style