This example demonstrates how to create and configure a date time box. Using the controls on the right you can modify various aspects of the date time box and its drop down calendar's appearance and behavior. NOV date time box is fully localizable, you can test how it looks for different cultures by selecting one from the cultures combo box on the right.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Globalization;
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.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NDateTimeBoxExample";
// 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_DateTimeBox = new NDateTimeBox();
m_DateTimeBox.VerticalPlacement = ENVerticalPlacement.Top;
m_DateTimeBox.HorizontalPlacement = ENHorizontalPlacement.Left;
m_DateTimeBox.SelectedDateChanged += OnDateTimeBoxSelectedColorChanged;
return m_DateTimeBox;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
stack.FillMode = ENStackFillMode.Last;
stack.FitMode = ENStackFitMode.Last;
NGroupBox groupBox = new NGroupBox("Culture:");
stack.Add(groupBox);
groupBox.Margins = new NMargins(0, 0, 0, 10);
// add the cultures combo box
string dateBoxCultureName = m_DateTimeBox.CultureName ?? m_DateTimeBox.CultureInfo.Name;
NComboBox culturesCombo = new NComboBox();
for (int i = 0; i < Cultures.Count; i++)
{
CultureInfo culture = Cultures[i];
NComboBoxItem item = new NComboBoxItem(NCultureInfo.GetEnglishCultureName(culture));
item.Tag = culture.Name;
culturesCombo.Items.Add(item);
if (culture.Name == dateBoxCultureName)
{
culturesCombo.SelectedIndex = i;
}
}
culturesCombo.SelectedIndexChanged += OnCultureComboSelectedIndexChanged;
groupBox.Content = culturesCombo;
NList editors = NDesigner.GetDesigner(m_DateTimeBox).CreateMemberEditors(
m_DateTimeBox,
NDateTimeBox.EnabledProperty,
NDateTimeBox.HighlightTodayProperty,
NDateTimeBox.HasTodayButtonProperty,
NDateTimeBox.ModeProperty,
NDateTimeBox.FormatProperty,
NDateTimeBox.SelectedDateProperty);
for (int i = 0; i < editors.Count; i++)
{
stack.Add(editors[i]);
}
m_EventsLog = new NExampleEventsLog();
stack.Add(m_EventsLog);
return new NUniSizeBoxGroup(stack);
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to create and configure a date time box. Using the controls on the right you can
modify various aspects of the date time box and its drop down calendar's appearance and behavior. NOV date time
box is fully localizable, you can test how it looks for different cultures by selecting one from the cultures
combo box on the right.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Date Time Box", "https://www.nevron.com/docs/openvision/ui-date-time-box.html"),
("Drop Down Edits Overview", "https://www.nevron.com/docs/openvision/ui-drop-down-edits-overview.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
private void OnDateTimeBoxSelectedColorChanged(NValueChangeEventArgs args)
{
DateTime newDate = (DateTime)args.NewValue;
m_EventsLog.LogEvent(newDate.ToString());
}
private void OnCultureComboSelectedIndexChanged(NValueChangeEventArgs args)
{
NComboBox combo = args.TargetNode as NComboBox;
NComboBoxItem selectedItem = combo.SelectedItem;
if (selectedItem == null)
return;
m_DateTimeBox.CultureName = (string)selectedItem.Tag;
}
#endregion
#region Fields
private NExampleEventsLog m_EventsLog;
private NDateTimeBox m_DateTimeBox;
#endregion
#region Static Methods
#endregion
#region Constants
private static readonly NList Cultures;
#endregion
#region Nested Types
private class NCultureNameComparer : IComparer
{
public int Compare(CultureInfo culture1, CultureInfo culture2)
{
string englishName1 = NCultureInfo.GetEnglishCultureName(culture1);
string englishName2 = NCultureInfo.GetEnglishCultureName(culture2);
return englishName1.CompareTo(englishName2);
}
}
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.DataStructures
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Editors
Imports Nevron.Nov.Globalization
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System
Imports System.Collections.Generic
Imports System.Globalization
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 - NDateTimeBoxExample"
' 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_DateTimeBox = New NDateTimeBox()
m_DateTimeBox.VerticalPlacement = ENVerticalPlacement.Top
m_DateTimeBox.HorizontalPlacement = ENHorizontalPlacement.Left
Me.m_DateTimeBox.SelectedDateChanged += AddressOf OnDateTimeBoxSelectedColorChanged
Return m_DateTimeBox
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
stack.FillMode = ENStackFillMode.Last
stack.FitMode = ENStackFitMode.Last
Dim groupBox As NGroupBox = New NGroupBox("Culture:")
stack.Add(groupBox)
groupBox.Margins = New NMargins(0, 0, 0, 10)
' add the cultures combo box
Dim dateBoxCultureName = If(m_DateTimeBox.CultureName, m_DateTimeBox.CultureInfo.Name)
Dim culturesCombo As NComboBox = New NComboBox()
For i = 0 To Cultures.Count - 1
Dim culture = Cultures(i)
Dim item As NComboBoxItem = New NComboBoxItem(NCultureInfo.GetEnglishCultureName(culture))
item.Tag = culture.Name
culturesCombo.Items.Add(item)
If Equals(culture.Name, dateBoxCultureName) Then
culturesCombo.SelectedIndex = i
End If
Next
culturesCombo.SelectedIndexChanged += AddressOf OnCultureComboSelectedIndexChanged
groupBox.Content = culturesCombo
Dim editors = NDesigner.GetDesigner(m_DateTimeBox).CreateMemberEditors(m_DateTimeBox, NInputElement.EnabledProperty, NDateTimeBox.HighlightTodayProperty, NDateTimeBox.HasTodayButtonProperty, NDateTimeBox.ModeProperty, NDateTimeBox.FormatProperty, NDateTimeBox.SelectedDateProperty)
For i = 0 To editors.Count - 1
stack.Add(editors(i))
Next
m_EventsLog = New NExampleEventsLog()
stack.Add(m_EventsLog)
Return New NUniSizeBoxGroup(stack)
End Function
Public Function GetExampleDescription() As String
Return "
This example demonstrates how to create and configure a date time box. Using the controls on the right you can
modify various aspects of the date time box and its drop down calendar's appearance and behavior. NOV date time
box is fully localizable, you can test how it looks for different cultures by selecting one from the cultures
combo box on the right.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Date Time Box", "https://www.nevron.com/docs/openvision/ui-date-time-box.html"), ("Drop Down Edits Overview", "https://www.nevron.com/docs/openvision/ui-drop-down-edits-overview.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnDateTimeBoxSelectedColorChanged(args As NValueChangeEventArgs)
Dim newDate As Date = args.NewValue
m_EventsLog.LogEvent(newDate.ToString())
End Sub
Private Sub OnCultureComboSelectedIndexChanged(args As NValueChangeEventArgs)
Dim combo As NComboBox = TryCast(args.TargetNode, NComboBox)
Dim selectedItem = combo.SelectedItem
If selectedItem Is Nothing Then Return
m_DateTimeBox.CultureName = CStr(selectedItem.Tag)
End Sub
#End Region
#Region "Fields"
Private m_EventsLog As NExampleEventsLog
Private m_DateTimeBox As NDateTimeBox
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
Private Shared ReadOnly Cultures As NList(Of CultureInfo)
#End Region
#Region "Nested Types"
Private Class NCultureNameComparer
Implements IComparer(Of CultureInfo)
Public Function Compare(culture1 As CultureInfo, culture2 As CultureInfo) As Integer Implements IComparer(Of CultureInfo).Compare
Dim englishName1 = NCultureInfo.GetEnglishCultureName(culture1)
Dim englishName2 = NCultureInfo.GetEnglishCultureName(culture2)
Return englishName1.CompareTo(englishName2)
End Function
End Class
#End Region
End Class