This example demonstrates how to create a table flow layout panel and add widgets to it. You can control the parameters of the layout algorithm using the controls to the right.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Presentation;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NTableFlowPanelExample";
// 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()
{
m_TablePanel = new NTableFlowPanel();
m_TablePanel.SetBorder(1, NColor.Red);
for (int i = 1; i <= 16; i++)
{
m_TablePanel.Add(new NButton("Button " + i.ToString()));
}
return m_TablePanel;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NList editors = NDesigner.GetDesigner(m_TablePanel).CreateMemberEditors(
m_TablePanel,
NTableFlowPanel.EnabledProperty,
NTableFlowPanel.HorizontalPlacementProperty,
NTableFlowPanel.VerticalPlacementProperty,
NTableFlowPanel.DirectionProperty,
NTableFlowPanel.VerticalSpacingProperty,
NTableFlowPanel.HorizontalSpacingProperty,
NTableFlowPanel.MaxOrdinalProperty,
NTableFlowPanel.RowFillModeProperty,
NTableFlowPanel.RowFitModeProperty,
NTableFlowPanel.ColFillModeProperty,
NTableFlowPanel.ColFitModeProperty,
NTableFlowPanel.InvertedProperty,
NTableFlowPanel.UniformWidthsProperty,
NTableFlowPanel.UniformHeightsProperty);
NStackPanel propertiesStack = new NStackPanel();
for (int i = 0; i < editors.Count; i++)
{
propertiesStack.Add(editors[i]);
}
stack.Add(new NGroupBox("Properties", new NUniSizeBoxGroup(propertiesStack)));
// items stack
NStackPanel itemsStack = new NStackPanel();
NButton addSmallItemButton = new NButton("Add Small Item");
addSmallItemButton.Click += OnAddSmallItemButtonClick;
itemsStack.Add(addSmallItemButton);
NButton addLargeItemButton = new NButton("Add Large Item");
addLargeItemButton.Click += OnAddLargeItemButtonClick;
itemsStack.Add(addLargeItemButton);
NButton addRandomItemButton = new NButton("Add Random Item");
addRandomItemButton.Click += OnAddRandomItemButtonClick;
itemsStack.Add(addRandomItemButton);
NButton removeAllItemsButton = new NButton("Remove All Items");
removeAllItemsButton.Click += OnRemoveAllItemsButtonClick;
itemsStack.Add(removeAllItemsButton);
stack.Add(new NGroupBox("Items", itemsStack));
return stack;
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to create a table flow layout panel and add
widgets to it. You can control the parameters of the layout algorithm
using the controls to the right.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Table Flow Panel", "https://www.nevron.com/docs/openvision/ui-table-flow-panel.html"),
("Panels Overview", "https://www.nevron.com/docs/openvision/ui-panels-overview.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
private void OnAddSmallItemButtonClick(NEventArgs args)
{
NButton item = new NButton("Small." + m_TablePanel.Count.ToString());
item.MinSize = new NSize(5, 5);
item.PreferredSize = new NSize(25, 25);
m_TablePanel.Add(item);
}
private void OnAddLargeItemButtonClick(NEventArgs args)
{
NButton item = new NButton("Large." + m_TablePanel.Count.ToString());
item.MinSize = new NSize(20, 20);
item.PreferredSize = new NSize(60, 60);
m_TablePanel.Add(item);
}
private void OnAddRandomItemButtonClick(NEventArgs args)
{
int range = 30;
Random rnd = new Random();
NButton item = new NButton("Random." + m_TablePanel.Count.ToString());
item.MinSize = new NSize(rnd.Next(range), rnd.Next(range));
item.PreferredSize = new NSize(rnd.Next(range) + range, rnd.Next(range) + range);
m_TablePanel.Add(item);
}
private void OnRemoveAllItemsButtonClick(NEventArgs args)
{
m_TablePanel.Clear();
}
#endregion
#region Fields
private NTableFlowPanel m_TablePanel;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Editors
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System
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 - NTableFlowPanelExample"
' 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
m_TablePanel = New NTableFlowPanel()
m_TablePanel.SetBorder(1, NColor.Red)
For i = 1 To 16
m_TablePanel.Add(New NButton("Button " & i.ToString()))
Next
Return m_TablePanel
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim editors = NDesigner.GetDesigner(m_TablePanel).CreateMemberEditors(m_TablePanel, NInputElement.EnabledProperty, NWidget.HorizontalPlacementProperty, NWidget.VerticalPlacementProperty, NTableFlowPanel.DirectionProperty, NTableFlowPanel.VerticalSpacingProperty, NTableFlowPanel.HorizontalSpacingProperty, NTableFlowPanel.MaxOrdinalProperty, NTableFlowPanel.RowFillModeProperty, NTableFlowPanel.RowFitModeProperty, NTableFlowPanel.ColFillModeProperty, NTableFlowPanel.ColFitModeProperty, NTableFlowPanel.InvertedProperty, NTableFlowPanel.UniformWidthsProperty, NTableFlowPanel.UniformHeightsProperty)
Dim propertiesStack As NStackPanel = New NStackPanel()
For i = 0 To editors.Count - 1
propertiesStack.Add(editors(i))
Next
stack.Add(New NGroupBox("Properties", New NUniSizeBoxGroup(propertiesStack)))
' items stack
Dim itemsStack As NStackPanel = New NStackPanel()
Dim addSmallItemButton As NButton = New NButton("Add Small Item")
addSmallItemButton.Click += AddressOf OnAddSmallItemButtonClick
itemsStack.Add(addSmallItemButton)
Dim addLargeItemButton As NButton = New NButton("Add Large Item")
addLargeItemButton.Click += AddressOf OnAddLargeItemButtonClick
itemsStack.Add(addLargeItemButton)
Dim addRandomItemButton As NButton = New NButton("Add Random Item")
addRandomItemButton.Click += AddressOf OnAddRandomItemButtonClick
itemsStack.Add(addRandomItemButton)
Dim removeAllItemsButton As NButton = New NButton("Remove All Items")
removeAllItemsButton.Click += AddressOf OnRemoveAllItemsButtonClick
itemsStack.Add(removeAllItemsButton)
stack.Add(New NGroupBox("Items", itemsStack))
Return stack
End Function
Public Function GetExampleDescription() As String
Return "
This example demonstrates how to create a table flow layout panel and add
widgets to it. You can control the parameters of the layout algorithm
using the controls to the right.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Table Flow Panel", "https://www.nevron.com/docs/openvision/ui-table-flow-panel.html"), ("Panels Overview", "https://www.nevron.com/docs/openvision/ui-panels-overview.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnAddSmallItemButtonClick(args As NEventArgs)
Dim item As NButton = New NButton("Small." & m_TablePanel.Count.ToString())
item.MinSize = New NSize(5, 5)
item.PreferredSize = New NSize(25, 25)
m_TablePanel.Add(item)
End Sub
Private Sub OnAddLargeItemButtonClick(args As NEventArgs)
Dim item As NButton = New NButton("Large." & m_TablePanel.Count.ToString())
item.MinSize = New NSize(20, 20)
item.PreferredSize = New NSize(60, 60)
m_TablePanel.Add(item)
End Sub
Private Sub OnAddRandomItemButtonClick(args As NEventArgs)
Dim range = 30
Dim rnd As Random = New Random()
Dim item As NButton = New NButton("Random." & m_TablePanel.Count.ToString())
item.MinSize = New NSize(rnd.Next(range), rnd.Next(range))
item.PreferredSize = New NSize(rnd.Next(range) + range, rnd.Next(range) + range)
m_TablePanel.Add(item)
End Sub
Private Sub OnRemoveAllItemsButtonClick(args As NEventArgs)
m_TablePanel.Clear()
End Sub
#End Region
#Region "Fields"
Private m_TablePanel As NTableFlowPanel
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class