{ // 该调用是 Windows.Forms 窗体设计器所必需的。 InitializeComponent(); tbMonth.ContextMenu = mnu ; tbYear.ContextMenu = mnu ; tbDay.ContextMenu = mnu ; this.Height = 21 ; this.Value = DateTime.Now ; this.DateFormat = "yyyy-MM-dd" ; if (!this.DesignMode) CreateCalendar() ; this.UpDown.Width = 16 ; this.Refresh() ; } private void CreateCalendar() { Calendar = new MonthCalendar() ; Calendar.Visible = true ; Calendar.DateSelected+=new DateRangeEventHandler(Calendar_DateSelected); frmCalendar = new Form() ; frmCalendar.FormBorderStyle = FormBorderStyle.None ; frmCalendar.TopMost = true ; frmCalendar.Width = 270 ; frmCalendar.Height = 145 ; frmCalendar.Controls.Add(Calendar) ; Calendar.Dock = DockStyle.Fill ; frmCalendar.StartPosition = FormStartPosition.Manual ; frmCalendar.Deactivate+=new EventHandler(Calendar_Leave); frmCalendar.ShowInTaskbar = false ; } private void Calendar_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e) { this.frmCalendar.Hide() ; this.Value = this.Calendar.SelectionStart ; this.tbDay.Focus() ; } private void Calendar_Leave(object sender, System.EventArgs e) { this.frmCalendar.Hide() ; //this.Value = this.Calendar.SelectionStart ; this.tbDay.Focus() ; } private void RefreshDisplay() { bool blGB = false ; string strChar = "" ; if (strDateFormat == "yyyy-MM-dd") strChar = "-" ; else if (strDateFormat == "yyyy.MM.dd") strChar = "." ; else if (strDateFormat == "yyyy/MM/dd") strChar = "/" ; else if (strDateFormat== "yyyy年MM月dd日") blGB = true ; else strChar = strFomatChar ; if (blGB) { lbSep1.Text = "年" ; lbSep2.Text = "月" ; lbSep3.Text = "日" ; } else { lbSep1.Text = strChar ; lbSep2.Text = strChar ; lbSep3.Text = "" ; } this.Refresh() ; } /// 猜你喜欢