英文:
Datetimepicker months and years only in VB.net
问题
在datetimepicker中,是否可以仅选择月份和年份而不选择日期?我没有看到任何属性可以移除日期选择。如果有人有想法,请分享。将不胜感激。谢谢 ![]()
英文:
It is possible in datetimepicker can pick months and years only without date? I didn't see any properties to remove the date pick. If someone have an idea please share. It would be appreciated. Thank you ![]()

答案1
得分: 1
The DateTimePicker.Value property is of type DateTime, so you will always get a DateTime from it, regardless of your preferences. You can choose to ignore the parts you don't need. If you only want the date, you can disregard the time portion. If you only want the month and year, you can ignore the day as well.
Regarding the control itself, you can set the ShowUpDown property to True, and the drop-down button will be replaced with spinner buttons. This allows the user to increment and decrement individual parts of the displayed value, rather than displaying the drop-down calendar. You can also set the Format to Custom and then specify the CustomFormat to display it in your desired format, for example, "yyyy/MM." The control will then display only the year and month, and the spinner buttons can be used to adjust them.
As mentioned, the Value property will still return a complete DateTime, but you can extract the Year and Month from it, or use the Text property of the control if you need it as a String.
After reviewing your image again, it seems that you may want to keep the drop-down calendar but display only the year and month sections. Unfortunately, this is not possible.
英文:
The DateTimePicker.Value property is type DateTime so you will always get a DateTime from that no matter what. You can just ignore the parts you don't want, of course. If you only want the date, you ignore the time portion. If you only want the month and year, you can ignore the day too.
As for the control itself, you can set the ShowUpDown property to True and then the drop-down button will be replaced with spinner buttons, so the user will be able to increment and decrement individual parts of the displayed value rather than display the drop-down calendar. You can also set the Format to Custom and then the CustomFormat to whatever you want displayed, e.g. "yyyy/MM". The control will then display just the year and the month and the spinner buttons can be used to set them.
As I said, you'll still get a full DateTime from the Value property but you can just get the Year and Month of that, or use the Text of the control if you actually want a String.
Looking at your image again, I'm thinking that maybe you want to keep the drop-down calendar but only the year and month sections. That is not possible.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论