Back to Devexpress

TimeSpanEdit Class

windowsforms-devexpress-dot-xtraeditors-d712e1c1.md

latest6.0 KB
Original Source

TimeSpanEdit Class

The editor to display and edit time intervals.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXLicenseWinFormsEditors]
public class TimeSpanEdit :
    TimeEdit
vb
<DXLicenseWinFormsEditors>
Public Class TimeSpanEdit
    Inherits TimeEdit

The following members return TimeSpanEdit objects:

Remarks

The TimeSpanEdit control is designed to represent data stored in the TimeSpan format.

The editor consists of the following visual elements:

Edit box

A text box that displays the textual representation of the current time span. The displayed text is formatted according to the TimeSpanEdit.Properties.DisplayFormat property settings.

If the TimeSpanEdit.Properties.ReadOnly setting is not enabled, users can modify the time span directly in the edit box without invoking the drop-down panel. When the editor is focused, the value is displayed according to the TimeSpanEdit.Properties.MaskSettings property.

Drop-down buttonA button that invokes the drop-down panel.Drop-down panelA panel that displays the current time span and allows users to modify it. The panel is in sync with the edit mask - users can only edit time parts allowed by the edit mask.

The TimeSpanEdit.Properties property provides access to a repository item that stores settings specific to the TimeSpanEdit control. See RepositoryItemTimeSpanEdit for more information.

Example

The following example displays the time left until the new year — subtracts one DateTime value from another and displays the result in the editor.

csharp
namespace timespan {
    public partial class Form1 : XtraForm {
        DateTime NYDate = new DateTime(2015, 1, 1, 0, 0, 0, 0);
        public Form1() {
            InitializeComponent();
            timeSpanEdit1.Properties.ReadOnly = false;
            timeSpanEdit1.Properties.MaskSettings.MaskExpression = "dd DD, hh HH, mm MM, ss SS";
            timeSpanEdit1.Properties.UseMaskAsDisplayFormat = true;
            RefreshTimer();
        }

        private void RefreshTimer() {
            DateTime currentDate = DateTime.Now;
            TimeSpan timeToNY = NYDate - currentDate;
            timeSpanEdit1.EditValue = timeToNY;
        }

        private void simpleButton1_Click(object sender, EventArgs e) {
            RefreshTimer();
        }

        private void timeSpanEdit1_EditValueChanged(object sender, EventArgs e) {
            labelControl1.Text = timeSpanEdit1.Properties.GetDisplayText(timeSpanEdit1.EditValue) + " left for the New Year!";
        }
    }
}
vb
Namespace timespan
    Partial Public Class Form1
        Inherits XtraForm

        Private NYDate As New Date(2015, 1, 1, 0, 0, 0, 0)
        Public Sub New()
            InitializeComponent()
            timeSpanEdit1.Properties.ReadOnly = False
            timeSpanEdit1.Properties.MaskSettings.MaskExpression = "dd DD, hh HH, mm MM, ss SS"
            timeSpanEdit1.Properties.UseMaskAsDisplayFormat = True
            RefreshTimer()
        End Sub

        Private Sub RefreshTimer()
            Dim currentDate As Date = Date.Now
            Dim timeToNY As TimeSpan = NYDate.Subtract(currentDate)
            timeSpanEdit1.EditValue = timeToNY
        End Sub

        Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
            RefreshTimer()
        End Sub

        Private Sub timeSpanEdit1_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
            labelControl1.Text = timeSpanEdit1.Properties.GetDisplayText(timeSpanEdit1.EditValue) & " left for the New Year!"
        End Sub
    End Class
End Namespace

Implements

IXtraResizableControl

Inheritance

Show 14 items

Object MarshalByRefObject Component Control DevExpress.XtraEditors.XtraControl ControlBase BaseControl BaseEdit TextEdit ButtonEdit PopupBaseEdit BaseSpinEdit TimeEdit TimeSpanEdit

See Also

TimeSpanEdit Members

DevExpress.XtraEditors Namespace