开发者

.NET Month Picker Control

Is there a winforms month-only picker control? I need to allow th开发者_JAVA百科e user to select the month regardless of the day of the month.

Thanks.


I don't know of any such control. You could add the months to a Listbox or Combobox and have them that way?


There isn't such standard control but I it easy to make it on you own , add all months to Drop Down control.


Just for fun, a month-names ComboBox in three lines:

comboBox1.DataSource = new BindingSource(
    System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthNames
        .Where(m => m != String.Empty)
        .Select((m, i) => new { Name = m, Index = i })
        .ToDictionary(x => x.Index, x => x.Name),
    null);
comboBox1.DisplayMember = "Value";
comboBox1.ValueMember = "Key";

Now comboBox1.SelectedValue will be 0..11 depdending on the month selected.


You can use DateTimePicker with custom format to enable just the month to be specified as following:

DateTimePicker dateTimePicker1 = new DateTimePicker();
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MM"; // for May, June, July etc. format
dateTimePicker1.ShowUpDown = true; // prevents the calendar from being displayed
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜