Mixed Content 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.

Mixed Content Example for WinForms Description

This example demonstrates how to create a list box and add items with various content to it - text only items, items with image and text, checkable items and so on. Using the controls to the right you can modify the appearance and the behavior of the list box.


List Box Mixed Content Example

C# Mixed Content Example Code for Nevron UserInterface for WinForms
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 - NListBoxMixedContentExample";

			// 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 list box
			m_ListBox = new NListBox();
			m_ListBox.HorizontalPlacement = ENHorizontalPlacement.Left;
			m_ListBox.PreferredSize = new NSize(200, 400);

			// Fill the image Box
			FillWithImageCheckBoxAndTitle();

			// Hook to list box selection events
			m_ListBox.Selection.Selected += OnListBoxItemSelected;
			m_ListBox.Selection.Deselected += OnListBoxItemDeselected;

			return m_ListBox;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			stack.FillMode = ENStackFillMode.Last;
			stack.FitMode = ENStackFitMode.Last;

			// Create the content type group box
			NEditor contentTypePropertyEditor = NDesigner.GetDesigner(this).CreateMemberEditor(this, ContentTypeProperty);
			stack.Add(contentTypePropertyEditor);

			// Create the properties group box
			NStackPanel propertiesStack = new NStackPanel();
			NList editors = NDesigner.GetDesigner(m_ListBox).CreateMemberEditors(m_ListBox,
				NWidget.EnabledProperty,
				NWidget.HorizontalPlacementProperty,
				NWidget.VerticalPlacementProperty,
				NScrollContentBase.HScrollModeProperty,
				NScrollContentBase.VScrollModeProperty,
				NScrollContentBase.NoScrollHAlignProperty,
				NScrollContentBase.NoScrollVAlignProperty,
				NListBox.IntegralVScrollProperty
			);

			for (int i = 0, count = editors.Count; i < count; i++)
			{
				propertiesStack.Add(editors[i]);
			}

			NGroupBox propertiesGroupBox = new NGroupBox("Properties", new NUniSizeBoxGroup(propertiesStack));
			stack.Add(propertiesGroupBox);

			// Create the events log
			m_EventsLog = new NExampleEventsLog();
			stack.Add(m_EventsLog);

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

This example demonstrates how to create a list box and add items with various content to it - text only items, items with image and text, checkable items and so on. Using the controls to the right you can modify the appearance and the behavior of the list box.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("List Box", "https://www.nevron.com/docs/openvision/ui-list-box.html"), ("Widget Elements", "https://www.nevron.com/docs/openvision/ui-widget-elements.html"), ("Containers Overview", "https://www.nevron.com/docs/openvision/ui-containers-overview.html"), ("Label", "https://www.nevron.com/docs/openvision/ui-label.html"), }; } #endregion #region Implementation private NListBoxItem CreateListBoxItem(int index, bool hasCheckBox, bool hasImage) { string text = "Item " + index.ToString(); if (hasCheckBox == false && hasImage == false) return new NListBoxItem(text); NStackPanel stack = new NStackPanel(); stack.Direction = ENHVDirection.LeftToRight; stack.HorizontalSpacing = 3; if (hasCheckBox) { NCheckBox checkBox = new NCheckBox(); checkBox.VerticalPlacement = ENVerticalPlacement.Center; stack.Add(checkBox); } if (hasImage) { stack.Add(CreateImageBox(index)); } NLabel label = new NLabel(text); label.VerticalPlacement = ENVerticalPlacement.Center; stack.Add(label); return new NListBoxItem(stack); } private void FillWithImageCheckBoxAndTitle() { m_ListBox.Items.Clear(); for (int i = 0; i < 100; i++) { int index = (i % 32) / 8; bool checkBox = index == 1 || index == 3; bool image = index == 2 || index == 3; m_ListBox.Items.Add(CreateListBoxItem(i, checkBox, image)); } } private NListBoxItem CreateDetailedListBoxItem(int index) { NDockPanel dock = new NDockPanel(); dock.HorizontalSpacing = 3; dock.Padding = new NMargins(0, 2, 0, 2); dock.Add(CreateImageBox(index)); // Add the title NLabel titleLabel = new NLabel("Item " + index.ToString()); titleLabel.Font = new NFont(NFontDescriptor.DefaultSansFamilyName, 10, ENFontStyle.Bold); NDockLayout.SetDockArea(titleLabel, ENDockArea.Top); dock.AddChild(titleLabel); // Add the description NLabel descriptionLabel = new NLabel("This is item " + index.ToString() + "'s description."); NDockLayout.SetDockArea(descriptionLabel, ENDockArea.Center); dock.AddChild(descriptionLabel); return new NListBoxItem(dock); } private void FillWithImageTitleAndDetails() { m_ListBox.Items.Clear(); for (int i = 0; i < 100; i++) { m_ListBox.Items.Add(CreateDetailedListBoxItem(i)); } } /// /// /// /// /// private static NImageBox CreateImageBox(int index) { string[] imageNames = new string[] { "Calendar", "Contacts", "Folders", "Journal", "Mail", "Notes", "Shortcuts", "Tasks" }; NEmbeddedResource[] imageResources = new NEmbeddedResource[] { Nevron.Nov.Examples.NResources.RIMG__16x16_Calendar_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Contacts_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Folders_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Journal_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Mail_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Notes_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Shortcuts_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Tasks_png }; // Add the image int imageIndex = index % imageNames.Length; string imageName = imageNames[imageIndex]; NImage icon = new NImage(new NEmbeddedResourceRef(imageResources[imageIndex])); NImageBox imageBox = new NImageBox(icon); imageBox.HorizontalPlacement = ENHorizontalPlacement.Center; imageBox.VerticalPlacement = ENVerticalPlacement.Center; NDockLayout.SetDockArea(imageBox, ENDockArea.Left); return imageBox; } #endregion #region Event Handlers private void OnListBoxItemSelected(NItemEventArgs args) { NListBoxItem item = args.Item; int index = item.GetAggregationInfo().Index; m_EventsLog.LogEvent("Selected Item: " + index.ToString()); } private void OnListBoxItemDeselected(NItemEventArgs args) { NListBoxItem item = args.Item; int index = item.GetAggregationInfo().Index; m_EventsLog.LogEvent("Deselected Item: " + index.ToString()); } /// /// Called when the ContentType property has changed. /// /// private void OnContentTypeChanged(NValueChangeData data) { switch ((ENListBoxContentType)data.NewValue) { case ENListBoxContentType.ImageCheckBoxAndTitle: FillWithImageCheckBoxAndTitle(); break; case ENListBoxContentType.ImageTitleAndDetails: FillWithImageTitleAndDetails(); break; default: throw new Exception("New ENListBoxContentType?"); } } #endregion #region Fields private NListBox m_ListBox; private NExampleEventsLog m_EventsLog; #endregion #region Static Methods #endregion #region Constants private const ENListBoxContentType defaultContentType = ENListBoxContentType.ImageCheckBoxAndTitle; #endregion #region Nested Types public enum ENListBoxContentType { ImageCheckBoxAndTitle, ImageTitleAndDetails } /// /// Designer for NListBoxMixedContent. /// public class NListBoxMixedContentDesigner : NDesigner { /// /// Default constructor. /// public NListBoxMixedContentDesigner() { SetMemberEditorFactory(ContentTypeProperty, NEnumPropertyEditor.VerticalRadioGroupFactory); } } #endregion } }

Download a fully functional C# (.cs) Mixed Content Example for WinForms Solution

VB.NET Mixed Content Example Code for Nevron UserInterface for WinForms
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.Presentation
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 - NListBoxMixedContentExample"

        ' 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 list box
            m_ListBox = New NListBox()
            m_ListBox.HorizontalPlacement = ENHorizontalPlacement.Left
            m_ListBox.PreferredSize = New NSize(200, 400)

            ' Fill the image Box
            FillWithImageCheckBoxAndTitle()

            ' Hook to list box selection events
            Me.m_ListBox.Selection.Selected += AddressOf OnListBoxItemSelected
            Me.m_ListBox.Selection.Deselected += AddressOf OnListBoxItemDeselected

            Return m_ListBox
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            stack.FillMode = ENStackFillMode.Last
            stack.FitMode = ENStackFitMode.Last

            ' Create the content type group box
            Dim contentTypePropertyEditor As NEditor = NDesigner.GetDesigner(CType(Me, NListBoxMixedContentExample)).CreateMemberEditor(Me, ContentTypeProperty)
            stack.Add(contentTypePropertyEditor)

            ' Create the properties group box
            Dim propertiesStack As NStackPanel = New NStackPanel()
            Dim editors = NDesigner.GetDesigner(m_ListBox).CreateMemberEditors(m_ListBox, NInputElement.EnabledProperty, NWidget.HorizontalPlacementProperty, NWidget.VerticalPlacementProperty, NScrollContentBase.HScrollModeProperty, NScrollContentBase.VScrollModeProperty, NScrollContentBase.NoScrollHAlignProperty, NScrollContentBase.NoScrollVAlignProperty, NListBox.IntegralVScrollProperty)

            Dim i = 0, count = editors.Count

            While i < count
                propertiesStack.Add(editors(i))
                i += 1
            End While

            Dim propertiesGroupBox As NGroupBox = New NGroupBox("Properties", New NUniSizeBoxGroup(propertiesStack))
            stack.Add(propertiesGroupBox)

            ' Create the events log
            m_EventsLog = New NExampleEventsLog()
            stack.Add(m_EventsLog)

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

This example demonstrates how to create a list box and add items with various content to it - text only items, items with image and text, checkable items and so on. Using the controls to the right you can modify the appearance and the behavior of the list box.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("List Box", "https://www.nevron.com/docs/openvision/ui-list-box.html"), ("Widget Elements", "https://www.nevron.com/docs/openvision/ui-widget-elements.html"), ("Containers Overview", "https://www.nevron.com/docs/openvision/ui-containers-overview.html"), ("Label", "https://www.nevron.com/docs/openvision/ui-label.html")} End Function #End Region #Region "Implementation" Private Function CreateListBoxItem(index As Integer, hasCheckBox As Boolean, hasImage As Boolean) As NListBoxItem Dim text As String = "Item " & index.ToString() If hasCheckBox = False AndAlso hasImage = False Then Return New NListBoxItem(text) Dim stack As NStackPanel = New NStackPanel() stack.Direction = ENHVDirection.LeftToRight stack.HorizontalSpacing = 3 If hasCheckBox Then Dim checkBox As NCheckBox = New NCheckBox() checkBox.VerticalPlacement = ENVerticalPlacement.Center stack.Add(checkBox) End If If hasImage Then stack.Add(CreateImageBox(index)) End If Dim label As NLabel = New NLabel(text) label.VerticalPlacement = ENVerticalPlacement.Center stack.Add(label) Return New NListBoxItem(stack) End Function Private Sub FillWithImageCheckBoxAndTitle() m_ListBox.Items.Clear() For i = 0 To 99 Dim index As Integer = (i Mod 32) / 8 Dim checkBox = index = 1 OrElse index = 3 Dim image = index = 2 OrElse index = 3 m_ListBox.Items.Add(CreateListBoxItem(i, checkBox, image)) Next End Sub Private Function CreateDetailedListBoxItem(index As Integer) As NListBoxItem Dim dock As NDockPanel = New NDockPanel() dock.HorizontalSpacing = 3 dock.Padding = New NMargins(0, 2, 0, 2) dock.Add(CreateImageBox(index)) ' Add the title Dim titleLabel As NLabel = New NLabel("Item " & index.ToString()) titleLabel.Font = New NFont(NFontDescriptor.DefaultSansFamilyName, 10, ENFontStyle.Bold) NDockLayout.SetDockArea(titleLabel, ENDockArea.Top) dock.AddChild(titleLabel) ' Add the description Dim descriptionLabel As NLabel = New NLabel("This is item " & index.ToString() & "'s description.") NDockLayout.SetDockArea(descriptionLabel, ENDockArea.Center) dock.AddChild(descriptionLabel) Return New NListBoxItem(dock) End Function Private Sub FillWithImageTitleAndDetails() m_ListBox.Items.Clear() For i = 0 To 99 m_ListBox.Items.Add(CreateDetailedListBoxItem(i)) Next End Sub ''' ''' ''' ''' ''' Private Shared Function CreateImageBox(index As Integer) As NImageBox Dim imageNames = New String() {"Calendar", "Contacts", "Folders", "Journal", "Mail", "Notes", "Shortcuts", "Tasks"} Dim imageResources = New NEmbeddedResource() {NResources.RIMG__16x16_Calendar_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Contacts_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Folders_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Journal_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Mail_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Notes_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Shortcuts_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Tasks_png} ' Add the image Dim imageIndex = index Mod imageNames.Length Dim imageName = imageNames(imageIndex) Dim icon As NImage = New NImage(New NEmbeddedResourceRef(imageResources(imageIndex))) Dim imageBox As NImageBox = New NImageBox(icon) imageBox.HorizontalPlacement = ENHorizontalPlacement.Center imageBox.VerticalPlacement = ENVerticalPlacement.Center NDockLayout.SetDockArea(imageBox, ENDockArea.Left) Return imageBox End Function #End Region #Region "Event Handlers" Private Sub OnListBoxItemSelected(args As NItemEventArgs(Of NListBoxItem)) Dim item = args.Item Dim index As Integer = item.GetAggregationInfo().Index m_EventsLog.LogEvent("Selected Item: " & index.ToString()) End Sub Private Sub OnListBoxItemDeselected(args As NItemEventArgs(Of NListBoxItem)) Dim item = args.Item Dim index As Integer = item.GetAggregationInfo().Index m_EventsLog.LogEvent("Deselected Item: " & index.ToString()) End Sub ''' ''' Called when the ContentType property has changed. ''' ''' Private Sub OnContentTypeChanged(data As NValueChangeData) Select Case data.NewValue Case ENListBoxContentType.ImageCheckBoxAndTitle FillWithImageCheckBoxAndTitle() Case ENListBoxContentType.ImageTitleAndDetails FillWithImageTitleAndDetails() Case Else Throw New Exception("New ENListBoxContentType?") End Select End Sub #End Region #Region "Fields" Private m_ListBox As NListBox Private m_EventsLog As NExampleEventsLog #End Region #Region "Static Methods" #End Region #Region "Constants" Private Const defaultContentType As ENListBoxContentType = ENListBoxContentType.ImageCheckBoxAndTitle #End Region #Region "Nested Types" Public Enum ENListBoxContentType ImageCheckBoxAndTitle ImageTitleAndDetails End Enum ''' ''' Designer for NListBoxMixedContent. ''' Public Class NListBoxMixedContentDesigner Inherits NDesigner ''' ''' Default constructor. ''' Public Sub New() SetMemberEditorFactory(ContentTypeProperty, NEnumPropertyEditor.VerticalRadioGroupFactory) End Sub End Class #End Region End Class

Download a fully functional VB.NET (.vb) Mixed Content Example for WinForms Solution