Winform程序中NumberUpdown控件作为年月选择框的代码增强
在NumberUpdown 的Valuechange事件中加入以下代码,自动处理12月加1,年度加1,01月减1,年份减1问题
int currentMonth = (int)(nudFlowMonth1.Value) % 100; int currentYear = (int)(nudFlowMonth1.Value) / 100; if (currentMonth > 12) { currentMonth = 1; currentYear++; nudFlowMonth1.Value = currentYear * 100 + currentMonth; } if (currentMonth < 1) { currentMonth = 12; currentYear--; nudFlowMonth1.Value = currentYear * 100 + currentMonth; }
活到老,学到老。

浙公网安备 33010602011771号