Table of Contents

Class TimeEditor

Namespace
Terminal.Gui.Views
Assembly
Terminal.Gui.dll

Provides time editing functionality using TextValidateField with culture-aware formatting.

public class TimeEditor : TextValidateField, IDisposable, ISupportInitializeNotification, ISupportInitialize, IValue<string>, IValue<TimeSpan>, IValue, IDesignable
Inheritance
TimeEditor
Implements
Inherited Members
Extension Methods

Remarks

TimeEditor extends TextValidateField with time-specific functionality:

<ul><li>Uses <xref href="Terminal.Gui.Views.TimeTextProvider" data-throw-if-not-resolved="false"></xref> for validation and formatting</li><li>
            Supports both 12-hour and 24-hour formats via <xref href="System.Globalization.DateTimeFormatInfo" data-throw-if-not-resolved="false"></xref>
        </li><li>Cursor automatically skips over separator characters</li><li>Supports AM/PM toggling for 12-hour formats</li><li>Auto-adjusts width based on time pattern</li></ul>

Usage Examples:

// Use default (current culture's long time pattern)
TimeEditor timeEditor = new () { Value = TimeSpan.FromHours (14.5) };
// en-US displays: " 2:30:00 PM"
// en-GB displays: " 14:30:00"

// Use specific culture's format timeEditor.Format = CultureInfo.GetCultureInfo ("de-DE").DateTimeFormat; // Displays: " 14:30:00"

// Want short time? Modify the LongTimePattern DateTimeFormatInfo format = (DateTimeFormatInfo)CultureInfo.CurrentCulture.DateTimeFormat.Clone (); format.LongTimePattern = format.ShortTimePattern; timeEditor.Format = format; // en-US displays: " 2:30 PM"

// Custom pattern with milliseconds DateTimeFormatInfo customFormat = (DateTimeFormatInfo)CultureInfo.CurrentCulture.DateTimeFormat.Clone (); customFormat.LongTimePattern = "HH:mm:ss.fff"; timeEditor.Format = customFormat; // Displays: " 14:30:00.000"

Constructors

TimeEditor()

Initializes a new instance of the TimeEditor class.

Properties

Format

Gets or sets the DateTimeFormatInfo used for time formatting.

Value

Gets or sets the current time value.

Methods

HandleProviderTextChanged(string, string)

Handles provider text changes for TimeEditor by raising TimeSpan-typed value events instead of string-typed events.

OnValueChanged(ValueChangedEventArgs<string?>)

Synchronizes the TimeSpan backing field when the base class Text property changes programmatically.

OnValueChanged(ValueChangedEventArgs<TimeSpan>)

Called when the Value has changed. Allows derived classes to react to value changes.

OnValueChanging(ValueChangingEventArgs<TimeSpan>)

Called when the Value is about to change. Allows derived classes to cancel the change.

Events

ValueChanged

Raised when Value has changed.

ValueChangedUntyped

Raised when Value has changed, providing the value as an un-typed object.

ValueChanging

Raised when Value is about to change. Set Handled to true to cancel the change.