Sadece-sub sınıflandırılır bunun için DomainUpDown
denetimi, burada kod:
class TimePicker : DomainUpDown
{
public TimePicker()
{
// build the list of times, in reverse order because the up/down buttons go the other way
for (double time = 23.5; time >= 0; time -= 0.5)
{
int hour = (int)time; // cast to an int, we only get the whole number which is what we want
int minutes = (int)((time - hour) * 60); // subtract the hour from the time variable to get the remainder of the hour, then multiply by 60 as .5 * 60 = 30 and 0 * 60 = 0
this.Items.Add(hour.ToString("00") + ":" + minutes.ToString("00")); // format the hour and minutes to always have two digits and concatenate them together with the colon between them, then add to the Items collection
}
this.SelectedIndex = Items.IndexOf("09:00"); // select a default time
this.Wrap = true; // this enables the picker to go to the first or last item if it is at the end of the list (i.e. if the user gets to 23:30 it wraps back around to 00:00 and vice versa)
}
}
şöyle formunuzda denetimi ekleyin:
TimePicker picker1;
public Form1()
{
InitializeComponent();
picker1 = new TimePicker();
picker1.Name = "timePicker";
picker1.Location = new Point(10, 10);
Controls.Add(picker1);
}
Sonra almak istediğinizde
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(picker1.SelectedItem.ToString()); // will show "09:00" when 09:00 is selected in the picker
}
: seçili zaman (burada bir düğme kullanın), biz sadece SelectedItem
özelliğini kullanın DomainUpDown
: http://msdn.microsoft.com/en-us/library/system.windows.forms.domainupdown.aspx
için Belgeler Kullandığınız kullanıcı arabirimi çerçevesi için bir şeyler bulabilirsiniz. Nedir bu, WPF, WinForms, ASP.NET, MVC/Razor? - Düzenle: Bu soru için vov, 4 upvotes. Niye ya? Neredeyse sıfır araştırma görüyorum. Orada bir sürü UI çerçevesi var. [Telerik] 'e (http://www.telerik.com/help/winforms/editors-timepicker-overview.html) veya [bu soruya] bir göz atın (http://stackoverflow.com/questions/1046268/time -sadece-toplayıcı-için-net-Win). – CodeCaster
Başıma atılan ilk şey Enumerable.Range idi, ama son çözümün neye benzediğini görmek isterdim. –
Üzgünüz @CodeCaster bkz. Düzenle – CR41G14