put two System.Windows.Forms.TrackBar Controls on a form: tBarHour, tBarMinute. Configure:
// tBarHour
//
this.tBarHour.LargeChange = 4;
this.tBarHour.Location = new System.Drawing.Point(280, 148);
this.tBarHour.Maximum = 23;
this.tBarHour.Name = "tBarHour";
this.tBarHour.Size = new System.Drawing.Size(375, 45);
this.tBarHour.TabIndex = 11;
this.tBarHour.Value = 12;
this.tBarHour.ValueChanged += new System.EventHandler(this.tBarHourMinute_ValueChanged);
//
// tBarMinute
//
this.tBarMinute.LargeChange = 10;
this.tBarMinute.Location = new System.Drawing.Point(280, 200);
this.tBarMinute.Maximum = 59;
this.tBarMinute.Name = "tBarMinute";
this.tBarMinute.Size = new System.Drawing.Size(375, 45);
this.tBarMinute.TabIndex = 12;
this.tBarMinute.ValueChanged += new System.EventHandler(this.tBarHourMinute_ValueChanged);
The Minimum TrackBar value is #0 by default. Set the ValueChanged event handler for both TrackBars to:
private TimeSpan tSpan;
private string tSpanStr;
private void tBarHourMinute_ValueChanged(object sender, EventArgs e)
{
tSpan = new TimeSpan(0, tBarHour.Value, tBarMinute.Value, 0);
tSpanStr = tSpan.ToString());
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali