TimeSpanEdit Class

The editor to display and edit time intervals.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v20.1.dll

Declaration

public class TimeSpanEdit :
    TimeEdit
Public Class TimeSpanEdit
    Inherits TimeEdit

Returned By

The RepositoryItemTimeSpanEdit.OwnerEdit property returns an instance of TimeSpanEdit.

Remarks

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

TimeSpanEdit - Visual Elements

The editor consists of the following visual elements:

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

Examples

The code below shows how to display the time left until the new year — subtract one DateTime value from another and display the result in the editor.

TimeSpanEdit - New Year Counter


namespace timespan {
    public partial class Form1 : XtraForm {
        DateTime NYDate = new DateTime(2015, 1, 1, 0, 0, 0, 0);
        public Form1() {
            InitializeComponent();
            timeSpanEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
            timeSpanEdit1.Properties.DisplayFormat.FormatString = "{0:dd} days, {0:hh} hours, {0:mm} minutes and {0:ss} seconds";
            timeSpanEdit1.Properties.ReadOnly = false;
            timeSpanEdit1.Properties.Mask.EditMask = "dd:HH:mm:ss";
            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!";
        }
    }
}
See Also