Wrap Flow Panel Example for Blazor

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

Wrap Flow Panel Example for Blazor Description

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


Wrap Flow Panel Example

C# Wrap Flow Panel Example Code for Nevron UserInterface for Blazor
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 - NWrapFlowPanelExample";

			// 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_WrapFlowPanel = new NWrapFlowPanel();
			m_WrapFlowPanel.SetBorder(1, NColor.Red);

            for (int i = 1; i <= 16; i++)
			{
				m_WrapFlowPanel.Add(new NButton("Button " + i.ToString()));
			}

			return m_WrapFlowPanel;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			
			NList editors = NDesigner.GetDesigner(m_WrapFlowPanel).CreateMemberEditors(
				m_WrapFlowPanel,
				NWrapFlowPanel.EnabledProperty,
				NWrapFlowPanel.HorizontalPlacementProperty,
				NWrapFlowPanel.VerticalPlacementProperty,
				NWrapFlowPanel.DirectionProperty,
				NWrapFlowPanel.VerticalSpacingProperty,
				NWrapFlowPanel.HorizontalSpacingProperty,
				NWrapFlowPanel.LaneFillModeProperty,
				NWrapFlowPanel.FillModeProperty,
				NWrapFlowPanel.FitModeProperty,
				NWrapFlowPanel.InvertedProperty,
				NWrapFlowPanel.UniformWidthsProperty,
				NWrapFlowPanel.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 wrap 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[] { ("Wrap Flow Panel", "https://www.nevron.com/docs/openvision/ui-wrap-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_WrapFlowPanel.Count.ToString()); item.MinSize = new NSize(5, 5); item.PreferredSize = new NSize(25, 25); m_WrapFlowPanel.Add(item); } private void OnAddLargeItemButtonClick(NEventArgs args) { NButton item = new NButton("Large." + m_WrapFlowPanel.Count.ToString()); item.MinSize = new NSize(20, 20); item.PreferredSize = new NSize(60, 60); m_WrapFlowPanel.Add(item); } private void OnAddRandomItemButtonClick(NEventArgs args) { int range = 30; Random rnd = new Random(); NButton item = new NButton("Random." + m_WrapFlowPanel.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_WrapFlowPanel.Add(item); } private void OnRemoveAllItemsButtonClick(NEventArgs args) { m_WrapFlowPanel.Clear(); } #endregion #region Fields NWrapFlowPanel m_WrapFlowPanel; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Wrap Flow Panel Example for Blazor Solution

Related Documentation Links