Reputation: 749
My application currently uses the DateTimePicker custom formatted to display HH:mm:ss.
How can I format it so to allow for tenths of a second? My second question is that when I tab into the datetimepicker, the Hours section is selected first by default, is there anyway to change this so that seconds are selected first by default? I noticed that If you click the updown arrows without tabbing into the control the seconds section is selected by default.
Any experts on the datetimepicker out there? Or does anyone have an ideas on an alternative I can use to implement these features?
Below is a picture of how it is formatted as well as the properties:
Upvotes: 0
Views: 2447
Reputation: 5291
You could try to force the DateTimePicker
to display milliseconds, but it will be a painful experience. You are better off using a MaskedTextBox
. You can download TimePicker.cs from sourceforge: https://sourceforge.net/projects/time-picker/
Here is some sample code:
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Form f = new Form();
var dp = new TimePicker("hh:mm:ss.f", true) { Location = new Point(100, 100) };
dp.ByValue[2] = false;
f.Controls.Add(dp);
var bt1 = new Button { Text = "Now", Location = new Point(110, 130) };
bt1.Click += delegate {
dp.Value = DateTime.Now;
};
int k = 0;
dp.ValueChanged += delegate {
bt1.Text = "Now " + (k++);
};
f.Controls.Add(bt1);
Application.Run(f);
}
Upvotes: 2
Reputation: 2271
This could work
Add a DomainUpDown control
Add a bunch of datetimes that vary by .1 seconds and display them as strings formatted to show miliseconds. Your user can then click up and down to see .1 second deltas
string dateString = "7/9/2015 9:32:45.126 AM";
DateTime dateValue = DateTime.Parse(dateString);
for (int i = 0; i < 5; i++)
{
dtPicker.Items.Add(dateValue.AddSeconds(.1*i).ToString("MM/dd/yyyy hh:mm:ss.fff tt"));
}
If you want to let the user pick say the hour first and then generate your datetime deltas from there it won't work as well. You could create multiple numeric controls, but at that point you might want to go down the path of extending the datetime picker like here.
Upvotes: 0