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
}
}