健康一贴灵,专注医药行业管理信息化

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;
            }

 

posted @ 2026-04-13 15:57  一贴灵  阅读(8)  评论(0)    收藏  举报
学以致用,效率第一