zoukankan      html  css  js  c++  java
  • C# 两个textBox控件调用同一个monthCalendar输入日期

    C# 多个textBox控件调用同一个monthCalendar输入日期:代码如下

    需要添加textBox1+textBox2+monthCalendar1控件

    DateTime FirstClick;
            int TextBoxNumber;
            private void textBox1_Click(object sender, EventArgs e)
            {
                this.TextBoxNumber = 1;
                this.monthCalendar1.Visible = true;
            }

            private void textBox2_Click(object sender, EventArgs e)
            {
                this.TextBoxNumber = 2;
                this.monthCalendar1.Visible = true;
            }

           /// <summary>
            /// 日期控件调用函数
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
            {
                if (this.TextBoxNumber == 1)
                {
                    MonthCalendarDoubleClick(this.textBox1, this.monthCalendar1);
                }
                else
                {
                    MonthCalendarDoubleClick(this.textBox2, this.monthCalendar1);
                }
            }      
            /// <summary>
            /// 双击日期控件调用函数
            /// </summary>
            /// <param name="SelectedTextBox"></param>
            /// <param name="monthCalendar"></param>
            private void MonthCalendarDoubleClick(TextBox SelectedTextBox, MonthCalendar monthCalendar)
            {
                DateTime SecondClick = DateTime.Now;//记录下第二次单击时间;
                string ClickSpan = Convert.ToString(SecondClick - FirstClick);//计算两次单击的时间间隔;格式为:00:00:00.1875000
                string Separator = ":.";
                char[] CharClickSpan = Separator.ToCharArray();
                string[] arrayClickSpan = ClickSpan.Split(CharClickSpan);
                if (arrayClickSpan.Length == 4 && arrayClickSpan[0].Equals("00") && arrayClickSpan[1].Equals("00") && arrayClickSpan[2].Equals("00"))
                {
                    if (Convert.ToInt32(arrayClickSpan[3].Substring(0, 3)) > SystemInformation.DoubleClickTime)//如果两次单击的时间间隔大于系统双击时间;
                    {
                        FirstClick = SecondClick;//赋第二次单击时间给第一次;
                    }
                    else
                    {
                        //两次单击的时间间隔小于或者等于喜欢双击时间
                        SelectedTextBox.Text = monthCalendar.SelectionStart.ToString("yyyy-MM-dd");//把双击选中的文本赋给TextBox;
                        this.monthCalendar1.Visible = false;
                    }
                }
                else
                {
                    FirstClick = SecondClick;
                }
            }

  • 相关阅读:
    TCP 基础知识
    Spring Boot 实战 —— 日志框架 Log4j2 SLF4J 的学习
    MySQL 实战笔记
    Java 基础
    RPM 包的构建
    RPM 包的构建
    9. 桶排序
    8. 基数排序
    7. 计数排序
    6. 快速排序
  • 原文地址:https://www.cnblogs.com/xqf222/p/3306856.html
Copyright © 2011-2022 走看看