Border Wall Example for WinForms

Nevron NOV UserInterface for WinForms ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WinForms UserInterface examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Border Wall Example for WinForms Description

This example demonstrates how to create different types of borders and apply them to widgets. It also demonstrates how to override the border wall of a widget and provide a custom one. Using the controls to the right you can change the type and appearance of the generated borders.


Border Wall Example

C# Border Wall Example Code for Nevron UserInterface for WinForms
Language: C#

using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
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 - NBorderWallExample";

			// 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 tab control for the different border walls
            NTab tab = new NTab();

            NTabPage boxBorderPage = new NTabPage("Box Border");
            tab.TabPages.Add(boxBorderPage);

            NTabPage crossBorderPage = new NTabPage("Cross Border");
            tab.TabPages.Add(crossBorderPage);

            NTabPage openBorderPage = new NTabPage("Opened Border");
            tab.TabPages.Add(openBorderPage);

            // create the three elements that demonstrate the border walls
            m_BoxBorderElement = new NCustomBorderWallWidget();
            boxBorderPage.Content = m_BoxBorderElement;
            m_BoxBorderElement.BorderWallType = ENCustomBorderWallType.Rectangle;

            m_CrossBorderElement = new NCustomBorderWallWidget();
            crossBorderPage.Content = m_CrossBorderElement;
            m_CrossBorderElement.BorderWallType = ENCustomBorderWallType.Cross;

            m_OpenedBorderElement = new NCustomBorderWallWidget();
            openBorderPage.Content = m_OpenedBorderElement;
            m_OpenedBorderElement.BorderWallType = ENCustomBorderWallType.Opened;

            // init the custom border elements
            NCustomBorderWallWidget[] elements = GetCustomBorderElements();
            NUIThemeColorMap colors = new NUIThemeColorMap(ENUIThemeScheme.WindowsClassic);
            for (int i = 0; i < elements.Length; i++)
            {
                elements[i].BorderThickness = new NMargins(2);
                elements[i].Border = NBorder.CreateRaised3DBorder(colors);
                elements[i].Margins = new NMargins(10);
            }

            return tab;
        }
        public NWidget CreateExampleControls()
        {
            NStackPanel stack = new NStackPanel();
            
            // create the predefined borders combo and populate it
            stack.Add(CreateLabel("Apply Predefined Border:"));
            m_PredefinedBorderCombo = new NComboBox();
            stack.Add(m_PredefinedBorderCombo);

            m_PredefinedBorderCombo.Items.Add(new NComboBoxItem("3D Raised Border"));
            m_PredefinedBorderCombo.Items.Add(new NComboBoxItem("3D Sunken Border"));
            m_PredefinedBorderCombo.Items.Add(new NComboBoxItem("Filled Border"));
            m_PredefinedBorderCombo.Items.Add(new NComboBoxItem("Filled Border with Outlines"));
            m_PredefinedBorderCombo.SelectedIndex = 0;
            m_PredefinedBorderCombo.SelectedIndexChanged += OnPredefinedBorderComboSelectedIndexChanged;

            // create the combos for the border thickness
            stack.Add(CreateLabel("Border Thickness:"));
            m_BorderThicknessCombo = CreateBorderSideThicknessCombo();
            stack.Add(m_BorderThicknessCombo);

            stack.Add(CreateLabel("Left Side Thickness:"));
            m_LeftSideThicknessCombo = CreateBorderSideThicknessCombo();
            stack.Add(m_LeftSideThicknessCombo);

            stack.Add(CreateLabel("Right Side Thickness:"));
            m_RightSideThicknessCombo = CreateBorderSideThicknessCombo();
            stack.Add(m_RightSideThicknessCombo);

            stack.Add(CreateLabel("Top Side Thickness:"));
            m_TopSideThicknessCombo = CreateBorderSideThicknessCombo();
            stack.Add(m_TopSideThicknessCombo);

            stack.Add(CreateLabel("Bottom Side Thickness:"));
            m_BottomSideThicknessCombo = CreateBorderSideThicknessCombo();
            stack.Add(m_BottomSideThicknessCombo);

            stack.Add(CreateLabel("Inner Corner Radius:"));
            m_InnerRadiusCombo = CreateCornerRadiusCombo();
            stack.Add(m_InnerRadiusCombo);

            stack.Add(CreateLabel("Outer Corner Radius:"));
            m_OuterRadiusCombo = CreateCornerRadiusCombo();
            stack.Add(m_OuterRadiusCombo);

            return stack;
        }
        public string GetExampleDescription()
        {
            return @"

This example demonstrates how to create different types of borders and apply them to widgets. It also demonstrates how to the border wall of a widget and provide a custom one. Using the controls to the right you can change the type and appearance of the generated borders.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Borders", "https://www.nevron.com/docs/openvision/ui-borders.html"), ("Box Elements", "https://www.nevron.com/docs/openvision/ui-box-elements.html"), }; } #endregion #region Implementation NLabel CreateLabel(string text) { NLabel label = new NLabel(text); label.HorizontalPlacement = ENHorizontalPlacement.Left; return label; } NComboBox CreateBorderSideThicknessCombo() { NComboBox combo = new NComboBox(); for (int i = 0; i < 30; i++) { combo.Items.Add(new NComboBoxItem(i.ToString() + " dip")); } combo.SelectedIndex = 2; combo.SelectedIndexChanged += OnSideThicknessComboSelectedIndexChanged; return combo; } NComboBox CreateCornerRadiusCombo() { NComboBox combo = new NComboBox(); for (int i = 0; i < 30; i++) { combo.Items.Add(new NComboBoxItem(i.ToString() + " dip")); } combo.SelectedIndex = 0; combo.SelectedIndexChanged += OnCornerRadiusComboSelectedIndexChanged; return combo; } NCustomBorderWallWidget[] GetCustomBorderElements() { return new NCustomBorderWallWidget[] { m_BoxBorderElement, m_CrossBorderElement, m_OpenedBorderElement }; } #endregion #region Event Handlers void OnPredefinedBorderComboSelectedIndexChanged(NValueChangeEventArgs args) { if (m_PredefinedBorderCombo.SelectedIndex == -1) return; double innerRadius = m_InnerRadiusCombo.SelectedIndex; double outerRadius = m_OuterRadiusCombo.SelectedIndex; // apply a predefined border NCustomBorderWallWidget[] elements = GetCustomBorderElements(); for (int i = 0; i < elements.Length; i++) { NBorder border = null; switch (m_PredefinedBorderCombo.SelectedIndex) { case 0: // 3D Raised Border border = NBorder.CreateRaised3DBorder(new NUIThemeColorMap(ENUIThemeScheme.WindowsClassic)); break; case 1: // 3D Sunken Border border = NBorder.CreateSunken3DBorder(new NUIThemeColorMap(ENUIThemeScheme.WindowsClassic)); break; case 2: // Filled Border border = NBorder.CreateFilledBorder(NColor.Red); break; case 3: // Filled Border with Outlines border = NBorder.CreateFilledBorder(new NColorFill(NColor.Blue), new NStroke(1, NColor.Black), new NStroke(1, NColor.Black)); break; } border.SetRadiuses(innerRadius, outerRadius); elements[i].Border = border; } } void OnSideThicknessComboSelectedIndexChanged(NValueChangeEventArgs args) { NComboBox combo = args.TargetNode as NComboBox; double sideThickness = combo.SelectedIndex; NMargins bt = m_BoxBorderElement.BorderThickness; if (combo == m_BorderThicknessCombo) { bt = new NMargins(sideThickness); } else if (combo == m_LeftSideThicknessCombo) { bt.Left = sideThickness; } else if (combo == m_RightSideThicknessCombo) { bt.Right = sideThickness; } else if (combo == m_TopSideThicknessCombo) { bt.Top = sideThickness; } else if (combo == m_BottomSideThicknessCombo) { bt.Bottom = sideThickness; } NCustomBorderWallWidget[] elements = GetCustomBorderElements(); for (int i = 0; i < elements.Length; i++) { elements[i].BorderThickness = bt; } } void OnCornerRadiusComboSelectedIndexChanged(NValueChangeEventArgs args) { OnPredefinedBorderComboSelectedIndexChanged(null); } #endregion #region Fields NCustomBorderWallWidget m_BoxBorderElement; NCustomBorderWallWidget m_CrossBorderElement; NCustomBorderWallWidget m_OpenedBorderElement; NComboBox m_PredefinedBorderCombo; NComboBox m_BorderThicknessCombo; NComboBox m_LeftSideThicknessCombo; NComboBox m_RightSideThicknessCombo; NComboBox m_TopSideThicknessCombo; NComboBox m_BottomSideThicknessCombo; NComboBox m_InnerRadiusCombo; NComboBox m_OuterRadiusCombo; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types /// /// Enumerates the demonstrated border walls /// public enum ENCustomBorderWallType { Rectangle, Cross, Opened } /// /// A widget that overrides the default border wall of widgets /// to demonstrate all possible corners and to demonstrate opened walls. /// public class NCustomBorderWallWidget : NWidget { #region Constructors public NCustomBorderWallWidget() { } static NCustomBorderWallWidget() { NCustomBorderWallWidgetSchema = NSchema.Create(typeof(NCustomBorderWallWidget), NWidget.NWidgetSchema); BorderWallTypeProperty = NCustomBorderWallWidgetSchema.AddSlot("BorderWallType", NDomType.FromType(typeof(ENCustomBorderWallType)), ENCustomBorderWallType.Rectangle); } #endregion #region Properties public ENCustomBorderWallType BorderWallType { get { return (ENCustomBorderWallType)GetValue(BorderWallTypeProperty); } set { SetValue(BorderWallTypeProperty, value); } } #endregion #region Protected Overrides - Border Wall protected override NBorderWall CreateBorderWall(NPaintVisitor visitor) { switch (BorderWallType) { case ENCustomBorderWallType.Rectangle: return base.CreateBorderWall(visitor); case ENCustomBorderWallType.Cross: return CreateCrossBorderWall(); case ENCustomBorderWallType.Opened: return CreateOpenedBorderWall(); default: throw new Exception("New ENCustomBorderWallType?"); } } #endregion #region Implementation - Border Wall private NBorderWall CreateCrossBorderWall() { NRectangle r0 = GetContentEdge(); NMargins bt = BorderThickness; bt.Left = Math.Min(bt.Left, r0.Width / 6); bt.Right = Math.Min(bt.Right, r0.Width / 6); bt.Top = Math.Min(bt.Top, r0.Height / 6); bt.Bottom = Math.Min(bt.Bottom, r0.Height / 6); NRectangle r1 = bt.GetInnerRect(r0); NRectangle r2 = NRectangle.FromLTRB( r1.X + r1.Width / 3 - (bt.Left / 2), r1.Y + r1.Height / 3 - (bt.Top / 2), r1.Right - r1.Width / 3 + (bt.Right / 2), r1.Bottom - r1.Height / 3 + (bt.Bottom / 2)); NRectangle r3 = bt.GetInnerRect(r2); double x0 = r0.X; double x1 = r1.X; double x2 = r2.X; double x3 = r3.X; double x4 = r3.Right; double x5 = r2.Right; double x6 = r1.Right; double x7 = r0.Right; double y0 = r0.Y; double y1 = r1.Y; double y2 = r2.Y; double y3 = r3.Y; double y4 = r3.Bottom; double y5 = r2.Bottom; double y6 = r1.Bottom; double y7 = r0.Bottom; NBorderWall wall = new NBorderWall(true); wall.AddLeftTopCorner(new NRectangle(x2, y0, bt.Left, bt.Top)); wall.AddTopSide(new NRectangle(x3, y0, x4 - x3, bt.Top)); wall.AddTopRightCorner(new NRectangle(x4, y0, bt.Right, bt.Top)); wall.AddRightSide(new NRectangle(x4, y1, bt.Right, y2 - y1)); wall.AddRightTopCorner(new NRectangle(x4, y2, bt.Right, bt.Top)); wall.AddTopSide(new NRectangle(x5, y2, x6 - x5, bt.Top)); wall.AddTopRightCorner(new NRectangle(x6, y2, bt.Right, bt.Top)); wall.AddRightSide(new NRectangle(x6, y3, bt.Right, y4 - y3)); wall.AddRightBottomCorner(new NRectangle(x6, y4, bt.Right, bt.Bottom)); wall.AddBottomSide(new NRectangle(x5, y4, x6 - x5, bt.Bottom)); wall.AddBottomRightCorner(new NRectangle(x4, y4, bt.Right, bt.Bottom)); wall.AddRightSide(new NRectangle(x4, y5, bt.Right, y6 - y5)); wall.AddRightBottomCorner(new NRectangle(x4, y6, bt.Right, bt.Bottom)); wall.AddBottomSide(new NRectangle(x3, y6, x4 - x3, bt.Bottom)); wall.AddBottomLeftCorner(new NRectangle(x2, y6, bt.Left, bt.Bottom)); wall.AddLeftSide(new NRectangle(x2, y5, bt.Left, y6 - y5)); wall.AddLeftBottomCorner(new NRectangle(x2, y4, bt.Left, bt.Bottom)); wall.AddBottomSide(new NRectangle(x1, y4, x2 - x1, bt.Bottom)); wall.AddBottomLeftCorner(new NRectangle(x0, y4, bt.Left, bt.Bottom)); wall.AddLeftSide(new NRectangle(x0, y3, bt.Left, y4 - y3)); wall.AddLeftTopCorner(new NRectangle(x0, y2, bt.Left, bt.Top)); wall.AddTopSide(new NRectangle(x1, y2, x2 - x1, bt.Top)); wall.AddTopLeftCorner(new NRectangle(x2, y2, bt.Left, bt.Top)); wall.AddLeftSide(new NRectangle(x2, y1, bt.Left, y2 - y1)); return wall; } private NBorderWall CreateOpenedBorderWall() { NRectangle outer = GetBorderEdge(); NRectangle inner = GetContentEdge(); NBorderWall wall = new NBorderWall(false); double leftSide = inner.X - outer.X; double topSide = inner.Y - outer.Y; double rightSide = outer.Right - inner.Right; double bottomSide = outer.Bottom - inner.Bottom; double topClipStart = inner.X + inner.Width / 3; double topClipEnd = inner.Right - inner.Width / 3; wall.AddTopSide(new NRectangle(topClipEnd, outer.Y, inner.Right - topClipEnd, topSide)); wall.AddTopRightCorner(new NRectangle(inner.Right, outer.Y, rightSide, topSide)); wall.AddRightSide(new NRectangle(inner.Right, inner.Y, rightSide, inner.Height)); wall.AddRightBottomCorner(new NRectangle(inner.Right, inner.Bottom, rightSide, bottomSide)); wall.AddBottomSide(new NRectangle(inner.X, inner.Bottom, inner.Width, bottomSide)); wall.AddBottomLeftCorner(new NRectangle(outer.X, inner.Bottom, leftSide, bottomSide)); wall.AddLeftSide(new NRectangle(outer.X, inner.Y, leftSide, inner.Height)); wall.AddLeftTopCorner(new NRectangle(outer.X, outer.Y, leftSide, topSide)); wall.AddTopSide(new NRectangle(inner.X, outer.Y, topClipStart - inner.X, topSide)); return wall; } #endregion #region Schema public static readonly NSchema NCustomBorderWallWidgetSchema; public static readonly NProperty BorderWallTypeProperty; #endregion } #endregion } }

Download a fully functional C# (.cs) Border Wall Example for WinForms Solution

VB.NET Border Wall Example Code for Nevron UserInterface for WinForms
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Imports System

Public Class Form1

#Region "Constructors"

    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        ' Set form title
        Text = "NOV WinForms - NBorderWallExample"

        ' 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)
        host.Dock = DockStyle.Fill
        Controls.Add(host)
    End Sub


#End Region

#Region "Example"

        Public Function CreateExampleContent() As NWidget
            ' create a tab control for the different border walls
            Dim tab As NTab = New NTab()

            Dim boxBorderPage As NTabPage = New NTabPage("Box Border")
            tab.TabPages.Add(boxBorderPage)

            Dim crossBorderPage As NTabPage = New NTabPage("Cross Border")
            tab.TabPages.Add(crossBorderPage)

            Dim openBorderPage As NTabPage = New NTabPage("Opened Border")
            tab.TabPages.Add(openBorderPage)

            ' create the three elements that demonstrate the border walls
            m_BoxBorderElement = New NCustomBorderWallWidget()
            boxBorderPage.Content = m_BoxBorderElement
            m_BoxBorderElement.BorderWallType = ENCustomBorderWallType.Rectangle

            m_CrossBorderElement = New NCustomBorderWallWidget()
            crossBorderPage.Content = m_CrossBorderElement
            m_CrossBorderElement.BorderWallType = ENCustomBorderWallType.Cross

            m_OpenedBorderElement = New NCustomBorderWallWidget()
            openBorderPage.Content = m_OpenedBorderElement
            m_OpenedBorderElement.BorderWallType = ENCustomBorderWallType.Opened

            ' init the custom border elements
            Dim elements As NCustomBorderWallWidget() = GetCustomBorderElements()
            Dim colors As NUIThemeColorMap = New NUIThemeColorMap(ENUIThemeScheme.WindowsClassic)
            For i = 0 To elements.Length - 1
                elements(i).BorderThickness = New NMargins(2)
                elements(i).Border = NBorder.CreateRaised3DBorder(colors)
                elements(i).Margins = New NMargins(10)
            Next

            Return tab
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()

            ' create the predefined borders combo and populate it
            stack.Add(CreateLabel("Apply Predefined Border:"))
            m_PredefinedBorderCombo = New NComboBox()
            stack.Add(m_PredefinedBorderCombo)

            m_PredefinedBorderCombo.Items.Add(New NComboBoxItem("3D Raised Border"))
            m_PredefinedBorderCombo.Items.Add(New NComboBoxItem("3D Sunken Border"))
            m_PredefinedBorderCombo.Items.Add(New NComboBoxItem("Filled Border"))
            m_PredefinedBorderCombo.Items.Add(New NComboBoxItem("Filled Border with Outlines"))
            m_PredefinedBorderCombo.SelectedIndex = 0
            Me.m_PredefinedBorderCombo.SelectedIndexChanged += AddressOf OnPredefinedBorderComboSelectedIndexChanged

            ' create the combos for the border thickness
            stack.Add(CreateLabel("Border Thickness:"))
            m_BorderThicknessCombo = CreateBorderSideThicknessCombo()
            stack.Add(m_BorderThicknessCombo)

            stack.Add(CreateLabel("Left Side Thickness:"))
            m_LeftSideThicknessCombo = CreateBorderSideThicknessCombo()
            stack.Add(m_LeftSideThicknessCombo)

            stack.Add(CreateLabel("Right Side Thickness:"))
            m_RightSideThicknessCombo = CreateBorderSideThicknessCombo()
            stack.Add(m_RightSideThicknessCombo)

            stack.Add(CreateLabel("Top Side Thickness:"))
            m_TopSideThicknessCombo = CreateBorderSideThicknessCombo()
            stack.Add(m_TopSideThicknessCombo)

            stack.Add(CreateLabel("Bottom Side Thickness:"))
            m_BottomSideThicknessCombo = CreateBorderSideThicknessCombo()
            stack.Add(m_BottomSideThicknessCombo)

            stack.Add(CreateLabel("Inner Corner Radius:"))
            m_InnerRadiusCombo = CreateCornerRadiusCombo()
            stack.Add(m_InnerRadiusCombo)

            stack.Add(CreateLabel("Outer Corner Radius:"))
            m_OuterRadiusCombo = CreateCornerRadiusCombo()
            stack.Add(m_OuterRadiusCombo)

            Return stack
        End Function
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to create different types of borders and apply them to widgets. It also demonstrates how to override the border wall of a widget and provide a custom one. Using the controls to the right you can change the type and appearance of the generated borders.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Borders", "https://www.nevron.com/docs/openvision/ui-borders.html"), ("Box Elements", "https://www.nevron.com/docs/openvision/ui-box-elements.html")} End Function #End Region #Region "Implementation" Private Function CreateLabel(text As String) As NLabel Dim label As NLabel = New NLabel(text) label.HorizontalPlacement = ENHorizontalPlacement.Left Return label End Function Private Function CreateBorderSideThicknessCombo() As NComboBox Dim combo As NComboBox = New NComboBox() For i = 0 To 29 combo.Items.Add(New NComboBoxItem(i.ToString() & " dip")) Next combo.SelectedIndex = 2 combo.SelectedIndexChanged += AddressOf OnSideThicknessComboSelectedIndexChanged Return combo End Function Private Function CreateCornerRadiusCombo() As NComboBox Dim combo As NComboBox = New NComboBox() For i = 0 To 29 combo.Items.Add(New NComboBoxItem(i.ToString() & " dip")) Next combo.SelectedIndex = 0 combo.SelectedIndexChanged += AddressOf OnCornerRadiusComboSelectedIndexChanged Return combo End Function Private Function GetCustomBorderElements() As NCustomBorderWallWidget() Return New NCustomBorderWallWidget() {m_BoxBorderElement, m_CrossBorderElement, m_OpenedBorderElement} End Function #End Region #Region "Event Handlers" Private Sub OnPredefinedBorderComboSelectedIndexChanged(args As NValueChangeEventArgs) If m_PredefinedBorderCombo.SelectedIndex = -1 Then Return Dim innerRadius As Double = m_InnerRadiusCombo.SelectedIndex Dim outerRadius As Double = m_OuterRadiusCombo.SelectedIndex ' apply a predefined border Dim elements As NCustomBorderWallWidget() = GetCustomBorderElements() For i = 0 To elements.Length - 1 Dim border As NBorder = Nothing Select Case m_PredefinedBorderCombo.SelectedIndex Case 0 ' 3D Raised Border border = NBorder.CreateRaised3DBorder(New NUIThemeColorMap(ENUIThemeScheme.WindowsClassic)) Case 1 ' 3D Sunken Border border = NBorder.CreateSunken3DBorder(New NUIThemeColorMap(ENUIThemeScheme.WindowsClassic)) Case 2 ' Filled Border border = NBorder.CreateFilledBorder(NColor.Red) Case 3 ' Filled Border with Outlines border = NBorder.CreateFilledBorder(New NColorFill(NColor.Blue), New NStroke(1, NColor.Black), New NStroke(1, NColor.Black)) End Select border.SetRadiuses(innerRadius, outerRadius) elements(i).Border = border Next End Sub Private Sub OnSideThicknessComboSelectedIndexChanged(args As NValueChangeEventArgs) Dim combo As NComboBox = TryCast(args.TargetNode, NComboBox) Dim sideThickness As Double = combo.SelectedIndex Dim bt As NMargins = m_BoxBorderElement.BorderThickness If combo Is m_BorderThicknessCombo Then bt = New NMargins(sideThickness) ElseIf combo Is m_LeftSideThicknessCombo Then bt.Left = sideThickness ElseIf combo Is m_RightSideThicknessCombo Then bt.Right = sideThickness ElseIf combo Is m_TopSideThicknessCombo Then bt.Top = sideThickness ElseIf combo Is m_BottomSideThicknessCombo Then bt.Bottom = sideThickness End If Dim elements As NCustomBorderWallWidget() = GetCustomBorderElements() For i = 0 To elements.Length - 1 elements(i).BorderThickness = bt Next End Sub Private Sub OnCornerRadiusComboSelectedIndexChanged(args As NValueChangeEventArgs) OnPredefinedBorderComboSelectedIndexChanged(Nothing) End Sub #End Region #Region "Fields" Private m_BoxBorderElement As NCustomBorderWallWidget Private m_CrossBorderElement As NCustomBorderWallWidget Private m_OpenedBorderElement As NCustomBorderWallWidget Private m_PredefinedBorderCombo As NComboBox Private m_BorderThicknessCombo As NComboBox Private m_LeftSideThicknessCombo As NComboBox Private m_RightSideThicknessCombo As NComboBox Private m_TopSideThicknessCombo As NComboBox Private m_BottomSideThicknessCombo As NComboBox Private m_InnerRadiusCombo As NComboBox Private m_OuterRadiusCombo As NComboBox #End Region #Region "Static Methods" #End Region #Region "Constants" #End Region #Region "Nested Types" ''' ''' Enumerates the demonstrated border walls ''' Public Enum ENCustomBorderWallType Rectangle Cross Opened End Enum ''' ''' A widget that overrides the default border wall of widgets ''' to demonstrate all possible corners and to demonstrate opened walls. ''' Public Class NCustomBorderWallWidget Inherits NWidget #Region "Constructors" Public Sub New() End Sub Shared Sub New() NCustomBorderWallWidgetSchema = NSchema.Create(GetType(NCustomBorderWallWidget), NWidgetSchema) BorderWallTypeProperty = NCustomBorderWallWidgetSchema.AddSlot("BorderWallType", NDomType.FromType(GetType(ENCustomBorderWallType)), ENCustomBorderWallType.Rectangle) End Sub #End Region #Region "Properties" Public Property BorderWallType As ENCustomBorderWallType Get Return GetValue(BorderWallTypeProperty) End Get Set(value As ENCustomBorderWallType) SetValue(BorderWallTypeProperty, value) End Set End Property #End Region #Region "Protected Overrides - Border Wall" Protected Overrides Function CreateBorderWall(visitor As NPaintVisitor) As NBorderWall Select Case BorderWallType Case ENCustomBorderWallType.Rectangle Return MyBase.CreateBorderWall(visitor) Case ENCustomBorderWallType.Cross Return CreateCrossBorderWall() Case ENCustomBorderWallType.Opened Return CreateOpenedBorderWall() Case Else Throw New Exception("New ENCustomBorderWallType?") End Select End Function #End Region #Region "Implementation - Border Wall" Private Function CreateCrossBorderWall() As NBorderWall Dim r0 As NRectangle = GetContentEdge() Dim bt As NMargins = MyBase.BorderThickness bt.Left = Math.Min(bt.Left, r0.Width / 6) bt.Right = Math.Min(bt.Right, r0.Width / 6) bt.Top = Math.Min(bt.Top, r0.Height / 6) bt.Bottom = Math.Min(bt.Bottom, r0.Height / 6) Dim r1 = bt.GetInnerRect(r0) Dim r2 = NRectangle.FromLTRB(r1.X + r1.Width / 3 - bt.Left / 2, r1.Y + r1.Height / 3 - bt.Top / 2, r1.Right - r1.Width / 3 + bt.Right / 2, r1.Bottom - r1.Height / 3 + bt.Bottom / 2) Dim r3 = bt.GetInnerRect(r2) Dim x0 = r0.X Dim x1 = r1.X Dim x2 = r2.X Dim x3 = r3.X Dim x4 = r3.Right Dim x5 = r2.Right Dim x6 = r1.Right Dim x7 = r0.Right Dim y0 = r0.Y Dim y1 = r1.Y Dim y2 = r2.Y Dim y3 = r3.Y Dim y4 = r3.Bottom Dim y5 = r2.Bottom Dim y6 = r1.Bottom Dim y7 = r0.Bottom Dim wall As NBorderWall = New NBorderWall(True) wall.AddLeftTopCorner(New NRectangle(x2, y0, bt.Left, bt.Top)) wall.AddTopSide(New NRectangle(x3, y0, x4 - x3, bt.Top)) wall.AddTopRightCorner(New NRectangle(x4, y0, bt.Right, bt.Top)) wall.AddRightSide(New NRectangle(x4, y1, bt.Right, y2 - y1)) wall.AddRightTopCorner(New NRectangle(x4, y2, bt.Right, bt.Top)) wall.AddTopSide(New NRectangle(x5, y2, x6 - x5, bt.Top)) wall.AddTopRightCorner(New NRectangle(x6, y2, bt.Right, bt.Top)) wall.AddRightSide(New NRectangle(x6, y3, bt.Right, y4 - y3)) wall.AddRightBottomCorner(New NRectangle(x6, y4, bt.Right, bt.Bottom)) wall.AddBottomSide(New NRectangle(x5, y4, x6 - x5, bt.Bottom)) wall.AddBottomRightCorner(New NRectangle(x4, y4, bt.Right, bt.Bottom)) wall.AddRightSide(New NRectangle(x4, y5, bt.Right, y6 - y5)) wall.AddRightBottomCorner(New NRectangle(x4, y6, bt.Right, bt.Bottom)) wall.AddBottomSide(New NRectangle(x3, y6, x4 - x3, bt.Bottom)) wall.AddBottomLeftCorner(New NRectangle(x2, y6, bt.Left, bt.Bottom)) wall.AddLeftSide(New NRectangle(x2, y5, bt.Left, y6 - y5)) wall.AddLeftBottomCorner(New NRectangle(x2, y4, bt.Left, bt.Bottom)) wall.AddBottomSide(New NRectangle(x1, y4, x2 - x1, bt.Bottom)) wall.AddBottomLeftCorner(New NRectangle(x0, y4, bt.Left, bt.Bottom)) wall.AddLeftSide(New NRectangle(x0, y3, bt.Left, y4 - y3)) wall.AddLeftTopCorner(New NRectangle(x0, y2, bt.Left, bt.Top)) wall.AddTopSide(New NRectangle(x1, y2, x2 - x1, bt.Top)) wall.AddTopLeftCorner(New NRectangle(x2, y2, bt.Left, bt.Top)) wall.AddLeftSide(New NRectangle(x2, y1, bt.Left, y2 - y1)) Return wall End Function Private Function CreateOpenedBorderWall() As NBorderWall Dim outer As NRectangle = GetBorderEdge() Dim inner As NRectangle = GetContentEdge() Dim wall As NBorderWall = New NBorderWall(False) Dim leftSide = inner.X - outer.X Dim topSide = inner.Y - outer.Y Dim rightSide = outer.Right - inner.Right Dim bottomSide = outer.Bottom - inner.Bottom Dim topClipStart = inner.X + inner.Width / 3 Dim topClipEnd = inner.Right - inner.Width / 3 wall.AddTopSide(New NRectangle(topClipEnd, outer.Y, inner.Right - topClipEnd, topSide)) wall.AddTopRightCorner(New NRectangle(inner.Right, outer.Y, rightSide, topSide)) wall.AddRightSide(New NRectangle(inner.Right, inner.Y, rightSide, inner.Height)) wall.AddRightBottomCorner(New NRectangle(inner.Right, inner.Bottom, rightSide, bottomSide)) wall.AddBottomSide(New NRectangle(inner.X, inner.Bottom, inner.Width, bottomSide)) wall.AddBottomLeftCorner(New NRectangle(outer.X, inner.Bottom, leftSide, bottomSide)) wall.AddLeftSide(New NRectangle(outer.X, inner.Y, leftSide, inner.Height)) wall.AddLeftTopCorner(New NRectangle(outer.X, outer.Y, leftSide, topSide)) wall.AddTopSide(New NRectangle(inner.X, outer.Y, topClipStart - inner.X, topSide)) Return wall End Function #End Region #Region "Schema" Public Shared ReadOnly NCustomBorderWallWidgetSchema As NSchema Public Shared ReadOnly BorderWallTypeProperty As NProperty #End Region End Class #End Region End Class

Download a fully functional VB.NET (.vb) Border Wall Example for WinForms Solution

Related Documentation Links