WPF textbox 鼠标滚动更新日期,text文本值更改

 

      /// <summary>
        /// 选择日期
        /// </summary>
        private void RQTxt_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (XZQTxt.IsSelectionActive && XZQTxt.Text != null)
                Math(e.Delta, XZQTxt);
        }

        /// <summary>
        /// 输入月份更新文本
        /// </summary>
        /// <param name="e">滚轮上翻(正)还是下翻(负)</param>
        /// <param name="text">事件发生前的文本值</param>
        public void Math(int e, TextBox time)
        {
            string text = time.Text;
            ShowTXT(time, e, text, text.Substring(4, 2), "31", "30");
            switch (text.Substring(4, 2))
            {
                case "05":
                    ShowTXT(time, e, text, "05", "31", "30");
                    break;
                case "06":
                    ShowTXT(time, e, text, "06", "30", "31");
                    break;
                case "07":
                    ShowTXT(time, e, text, "07", "31", "30");
                    break;
                case "08":
                    ShowTXT(time, e, text, "08", "31", "31");
                    break;
                case "09":
                    ShowTXT(time, e, text, "09", "30", "31");
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 显示文本
        /// </summary>
        /// <param name="e">滚轮上翻(正)还是下翻(负)</param>
        /// <param name="text">事件发生前的文本值</param>
        /// <param name="YF">月份</param>
        /// <param name="ZYS">这月的天数</param>
        /// <param name="SYS">上月的天数</param>
        public void ShowTXT(TextBox time, int e, string text, string YF, string ZYS, string SYS)
        {
            if (Convert.ToInt32(text.Substring(6, 2)) + (e / 120) > Convert.ToInt32(ZYS) && e > 0)
                time.Text = text.Substring(0, 4) + "0" + (Convert.ToInt32(YF.Substring(1)) + 1) + "01";
            else if ((Convert.ToInt32(text) + (e / 120)).ToString().Substring(6, 2) == "00" && e < 0)
                time.Text = text.Substring(0, 4) + "0" + (Convert.ToInt32(YF.Substring(1)) - 1) + SYS;
            else
                time.Text = (Convert.ToInt32(text) + e / 120).ToString();
        }

 

posted @ 2019-06-27 16:42  紫晶城  阅读(537)  评论(0编辑  收藏  举报