在组合框中设置表单加载的当前月份 [英] Set current month on form load in combobox
本文介绍了在组合框中设置表单加载的当前月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像jan,feb,march这样的月份的组合框,我想在表格载荷上显示当前月份
i have combobox which is having months like jan, feb , march, i want to display current month on form load
推荐答案
不一定要在表单加载 - 请尝试使用Form.Shown事件:
Don't necessarily do it in form load - try the Form.Shown event instead:
MyMonthsComboBox.SelectedText = DateTime.Now.ToString("MMMM")
使用以下行查找当前月份数
Use following line to find current month number
int month = System.DateTime.Now.Month;
在为组合添加月份时,使用值作为月份索引添加。 />
现在将上个月分配给组合框的该值。
While adding months to combo, add with value as Month index.
Now assign above month to that value for combo box.
尝试
DateTime.Today.ToString("MMMM")
对于所有格式,请参阅 - 自定义日期和时间格式字符串 [ ^ ]。
这篇关于在组合框中设置表单加载的当前月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文