Demonstrates how to add bullets lists in text content.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Diagram;
using Nevron.Nov.Diagram.Shapes;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Text;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NBulletListsExample";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
public NWidget CreateExampleContent()
{
// Create a simple drawing
NDrawingViewWithRibbon drawingViewWithRibbon = new NDrawingViewWithRibbon();
m_DrawingView = drawingViewWithRibbon.View;
m_DrawingView.Document.HistoryService.Pause();
try
{
InitDiagram(m_DrawingView.Document);
}
finally
{
m_DrawingView.Document.HistoryService.Resume();
}
return drawingViewWithRibbon;
}
public NWidget CreateExampleControls()
{
return null;
}
public string GetExampleDescription()
{
return @"Demonstrates how to add bullets lists in text content.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Text Block", "https://www.nevron.com/docs/openvision/diagram-text-block.html"),
("Rich Text Bullet Lists", "https://www.nevron.com/docs/openvision/rich-text-bullet-lists.html"),
("Rich Text Paragraphs", "https://www.nevron.com/docs/openvision/rich-text-paragraphs.html"),
};
}
private void InitDiagram(NDrawingDocument drawingDocument)
{
NDrawing drawing = drawingDocument.Content;
// hide the grid
drawing.ScreenVisibility.ShowGrid = false;
NShape shape1 = new NBasicShapeFactory().CreateShape(ENBasicShape.Rectangle);
shape1.SetBounds(10, 10, 600, 1000);
NTextBlock textBlock = new NTextBlock();
shape1.TextBlock = textBlock;
textBlock.Padding = new NMargins(20);
textBlock.Content.Blocks.Clear();
textBlock.Content.HorizontalAlignment = ENAlign.Left;
AddFormattedTextToContent(textBlock.Content);
drawing.ActivePage.Items.Add(shape1);
}
#endregion
#region Implementation
#endregion
#region Event Handlers
#endregion
#region Fields
private NDrawingView m_DrawingView;
#endregion
#region Static Methods
///
/// Adds rich formatted text to the specified text block content
///
///
private static void AddFormattedTextToContent(NTextBlockContent content)
{
content.Blocks.Add(GetTitleParagraph("Bullet lists allow you to apply automatic numbering on paragraphs or groups of blocks.", 1));
// setting bullet list template type
{
content.Blocks.Add(GetTitleParagraph("Following are bullet lists with different formatting", 2));
ENBulletListTemplateType[] values = NEnum.GetValues();
string itemText = "Bullet List Item";
for (int i = 0; i < values.Length - 1; i++)
{
NGroupBlock group = new NGroupBlock();
content.Blocks.Add(group);
group.MarginTop = 10;
group.MarginBottom = 10;
NBulletList bulletList = new NBulletList(values[i]);
content.BulletLists.Add(bulletList);
for (int j = 0; j < 3; j++)
{
NParagraph paragraph = new NParagraph(itemText + j.ToString());
NBulletInline bullet = new NBulletInline();
bullet.List = bulletList;
paragraph.Bullet = bullet;
group.Blocks.Add(paragraph);
}
}
}
// nested bullet lists
{
content.Blocks.Add(GetTitleParagraph("Following is an example of bullets with different bullet level", 2));
NBulletList bulletList = new NBulletList(ENBulletListTemplateType.Decimal);
content.BulletLists.Add(bulletList);
NGroupBlock group = new NGroupBlock();
content.Blocks.Add(group);
for (int i = 0; i < 3; i++)
{
NParagraph par = new NParagraph("Bullet List Item" + i.ToString(), bulletList, 0);
group.Blocks.Add(par);
for (int j = 0; j < 2; j++)
{
NParagraph nestedPar = new NParagraph("Nested Bullet List Item" + i.ToString(), bulletList, 1);
nestedPar.MarginLeft = 10;
group.Blocks.Add(nestedPar);
}
}
}
}
internal static NParagraph GetTitleParagraphNoBorder(string text, int level)
{
double fontSize = 10;
ENFontStyle fontStyle = ENFontStyle.Regular;
switch (level)
{
case 1:
fontSize = 16;
fontStyle = ENFontStyle.Bold;
break;
case 2:
fontSize = 10;
fontStyle = ENFontStyle.Bold;
break;
}
NParagraph paragraph = new NParagraph();
paragraph.HorizontalAlignment = ENAlign.Left;
paragraph.FontSize = fontSize;
paragraph.FontStyle = fontStyle;
NTextInline textInline = new NTextInline(text);
textInline.FontStyle = fontStyle;
textInline.FontSize = fontSize;
paragraph.Inlines.Add(textInline);
return paragraph;
}
///
/// Gets a paragraph with title formatting
///
///
///
internal static NParagraph GetTitleParagraph(string text, int level)
{
NColor color = NColor.Black;
NParagraph paragraph = GetTitleParagraphNoBorder(text, level);
paragraph.HorizontalAlignment = ENAlign.Left;
paragraph.Border = CreateLeftTagBorder(color);
paragraph.BorderThickness = new NMargins(5.0, 0.0, 0.0, 0.0);
return paragraph;
}
///
/// Creates a left tag border with the specified border
///
///
///
private static NBorder CreateLeftTagBorder(NColor color)
{
NBorder border = new NBorder();
border.LeftSide = new NBorderSide();
border.LeftSide.Fill = new NColorFill(color);
return border;
}
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Diagram
Imports Nevron.Nov.Diagram.Shapes
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.Text
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Class MainWindow
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Title = "NOV WPF - NBulletListsExample"
' Create the NOV example and its controls
Dim exampleContent As NWidget = CreateExampleContent()
Dim exampleControls As NWidget = CreateExampleControls()
If Not exampleControls Is Nothing Then
exampleControls.PreferredWidth = 300
End If
' Place the example and its controls in a pair box
Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
pairBox.FillMode = ENStackFillMode.First
pairBox.FitMode = ENStackFitMode.First
pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)
' Host the example in the form
Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
Content = host
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
' Create a simple drawing
Dim drawingViewWithRibbon As NDrawingViewWithRibbon = New NDrawingViewWithRibbon()
m_DrawingView = drawingViewWithRibbon.View
m_DrawingView.Document.HistoryService.Pause()
Try
InitDiagram(m_DrawingView.Document)
Finally
m_DrawingView.Document.HistoryService.Resume()
End Try
Return drawingViewWithRibbon
End Function
Public Function CreateExampleControls() As NWidget
Return Nothing
End Function
Public Function GetExampleDescription() As String
Return "Demonstrates how to add bullets lists in text content.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Text Block", "https://www.nevron.com/docs/openvision/diagram-text-block.html"), ("Rich Text Bullet Lists", "https://www.nevron.com/docs/openvision/rich-text-bullet-lists.html"), ("Rich Text Paragraphs", "https://www.nevron.com/docs/openvision/rich-text-paragraphs.html")}
End Function
Private Sub InitDiagram(drawingDocument As NDrawingDocument)
Dim drawing = drawingDocument.Content
' hide the grid
drawing.ScreenVisibility.ShowGrid = False
Dim shape1 As NShape = New NBasicShapeFactory().CreateShape(ENBasicShape.Rectangle)
shape1.SetBounds(10, 10, 600, 1000)
Dim textBlock As NTextBlock = New NTextBlock()
shape1.TextBlock = textBlock
textBlock.Padding = New NMargins(20)
textBlock.Content.Blocks.Clear()
textBlock.Content.HorizontalAlignment = ENAlign.Left
AddFormattedTextToContent(textBlock.Content)
drawing.ActivePage.Items.Add(shape1)
End Sub
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
Private m_DrawingView As NDrawingView
#End Region
#Region "Static Methods"
'''
''' Adds rich formatted text to the specified text block content
'''
'''
Private Shared Sub AddFormattedTextToContent(content As NTextBlockContent)
content.Blocks.Add(GetTitleParagraph("Bullet lists allow you to apply automatic numbering on paragraphs or groups of blocks.", 1))
' setting bullet list template type
If True Then
content.Blocks.Add(GetTitleParagraph("Following are bullet lists with different formatting", 2))
Dim values As ENBulletListTemplateType() = NEnum.GetValues(Of ENBulletListTemplateType)()
Dim itemText = "Bullet List Item"
For i = 0 To values.Length - 1 - 1
Dim group As NGroupBlock = New NGroupBlock()
content.Blocks.Add(group)
group.MarginTop = 10
group.MarginBottom = 10
Dim bulletList As NBulletList = New NBulletList(values(i))
content.BulletLists.Add(bulletList)
For j = 0 To 2
Dim paragraph As NParagraph = New NParagraph(itemText & j.ToString())
Dim bullet As NBulletInline = New NBulletInline()
bullet.List = bulletList
paragraph.Bullet = bullet
group.Blocks.Add(paragraph)
Next
Next
End If
' nested bullet lists
If True Then
content.Blocks.Add(GetTitleParagraph("Following is an example of bullets with different bullet level", 2))
Dim bulletList As NBulletList = New NBulletList(ENBulletListTemplateType.Decimal)
content.BulletLists.Add(bulletList)
Dim group As NGroupBlock = New NGroupBlock()
content.Blocks.Add(group)
For i = 0 To 2
Dim par As NParagraph = New NParagraph("Bullet List Item" & i.ToString(), bulletList, 0)
group.Blocks.Add(par)
For j = 0 To 1
Dim nestedPar As NParagraph = New NParagraph("Nested Bullet List Item" & i.ToString(), bulletList, 1)
nestedPar.MarginLeft = 10
group.Blocks.Add(nestedPar)
Next
Next
End If
End Sub
Friend Shared Function GetTitleParagraphNoBorder(text As String, level As Integer) As NParagraph
Dim fontSize As Double = 10
Dim fontStyle = ENFontStyle.Regular
Select Case level
Case 1
fontSize = 16
fontStyle = ENFontStyle.Bold
Case 2
fontSize = 10
fontStyle = ENFontStyle.Bold
End Select
Dim paragraph As NParagraph = New NParagraph()
paragraph.HorizontalAlignment = ENAlign.Left
paragraph.FontSize = fontSize
paragraph.FontStyle = fontStyle
Dim textInline As NTextInline = New NTextInline(text)
textInline.FontStyle = fontStyle
textInline.FontSize = fontSize
paragraph.Inlines.Add(textInline)
Return paragraph
End Function
'''
''' Gets a paragraph with title formatting
'''
'''
'''
Friend Shared Function GetTitleParagraph(text As String, level As Integer) As NParagraph
Dim color = NColor.Black
Dim paragraph = GetTitleParagraphNoBorder(text, level)
paragraph.HorizontalAlignment = ENAlign.Left
paragraph.Border = CreateLeftTagBorder(color)
paragraph.BorderThickness = New NMargins(5.0, 0.0, 0.0, 0.0)
Return paragraph
End Function
'''
''' Creates a left tag border with the specified border
'''
'''
'''
Private Shared Function CreateLeftTagBorder(color As NColor) As NBorder
Dim border As NBorder = New NBorder()
border.LeftSide = New NBorderSide()
border.LeftSide.Fill = New NColorFill(color)
Return border
End Function
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class