C# 为 .net winform 寻找月/年选择器控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1608792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
looking for a month/year selector control for .net winform
提问by Brad
I am looking for a month selector control for a .net 2 winform.
我正在寻找 .net 2 winform 的月份选择器控件。
采纳答案by Donut
Use DateTimePicker
. You can use a custom formatto enable just the month and year to be specified.
使用DateTimePicker
. 您可以使用自定义格式来仅指定月份和年份。
Example:
例子:
DateTimePicker dateTimePicker1 = new DateTimePicker();
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MM yyyy";
dateTimePicker1.ShowUpDown = true; // to prevent the calendar from being displayed
See this MSDN articlefor more information.
有关更多信息,请参阅此 MSDN 文章。
Edit:
To prevent the calendar from being displayed, set the ShowUpDown
property on the DateTimePicker
to true
. This will prevent the calendar from being displayed and (in conjunction with a CustomFormat
) allow you to set just the month and year by using the up/down buttons.
编辑:
要防止显示日历,请将 上的ShowUpDown
属性设置DateTimePicker
为true
。这将阻止显示日历,并且(与 a 结合CustomFormat
)允许您使用向上/向下按钮仅设置月份和年份。