This example demonstrates how to create a pair box. The pair box is a widget, which consists of 2 other widgets - Box1 and Box2. You can change the relative alignment, the spacing and the size mode of this widgets 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.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NPairBoxExample";
// 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_PairBox = new NPairBox(CreateBoxContent("Box 1", NColor.Blue), CreateBoxContent("Box 2", NColor.Red));
m_PairBox.HorizontalPlacement = ENHorizontalPlacement.Left;
m_PairBox.VerticalPlacement = ENVerticalPlacement.Top;
// The Spacing property is automatically set from the UI theme to NDesign.HorizontalSpacing,
// so you don't need to set it. It is set here only for the purposes of the example.
m_PairBox.Spacing = NDesign.HorizontalSpacing;
return m_PairBox;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NList editors = NDesigner.GetDesigner(m_PairBox).CreateMemberEditors(m_PairBox,
NPairBox.EnabledProperty,
NPairBox.HorizontalPlacementProperty,
NPairBox.VerticalPlacementProperty,
NPairBox.BoxesRelationProperty,
NPairBox.FitModeProperty,
NPairBox.FillModeProperty,
NPairBox.SpacingProperty);
for (int i = 0, count = editors.Count; i < count; i++)
{
stack.Add(editors[i]);
}
return new NUniSizeBoxGroup(stack);
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to create a pair box. The pair box is a widget, which consists of 2 other widgets - Box1 and Box2.
You can change the relative alignment, the spacing and the size mode of this widgets using the controls to the right.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Pair Box", "https://www.nevron.com/docs/openvision/ui-pair-box.html"),
("Containers Overview", "https://www.nevron.com/docs/openvision/ui-containers-overview.html"),
};
}
#endregion
#region Implementation
private NWidget CreateBoxContent(string text, NColor borderColor)
{
NLabel label = new NLabel(text);
label.HorizontalPlacement = ENHorizontalPlacement.Center;
label.VerticalPlacement = ENVerticalPlacement.Center;
NContentHolder contentElement = new NContentHolder(label);
contentElement.Border = NBorder.CreateFilledBorder(borderColor);
contentElement.BorderThickness = new NMargins(1);
contentElement.Padding = new NMargins(2);
return contentElement;
}
#endregion
#region Event Handlers
#endregion
#region Fields
private NPairBox m_PairBox;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}