增加控件及注册绑定控件!

      private void initializeControls()
      {
         #region 增加 日期
         
         DateTimePicker dtpStart = new DateTimePicker();
         //dtpStart.Format = DateTimePickerFormat.Custom;//自动设置
         //dtpStart.CustomFormat = "MM月dd日";//自定义格式 
         dtpStart.Format = DateTimePickerFormat.Short;
         dtpStart.Width = 120;
         dtpStart.ShowCheckBox = true;
         Controls.Add(dtpStart);
         this.toolStrip1.Items.Insert(1, new ToolStripControlHost(dtpStart));

         DateTimePicker dtpEnd = new DateTimePicker();
         //dtpEnd.Format = DateTimePickerFormat.Custom;//自动设置
         //dtpEnd.CustomFormat = "MM月dd日";//自定义格式 
         dtpEnd.Format = DateTimePickerFormat.Short;
         dtpEnd.Width = 120;
         dtpEnd.ShowCheckBox = true;
         Controls.Add(dtpEnd);
         this.toolStrip1.Items.Insert(3, new ToolStripControlHost(dtpEnd));

         #endregion

         //先注册声明一个事件绑定:
         dtpStart.MouseEnter += new EventHandler(dtpStart_MouseEnter);
         dtpEnd.MouseEnter += new EventHandler(dtpEnd_MouseEnter );
      }



      private void dtpStart_MouseEnter(object sender, EventArgs e)
      {
         toolTip1.SetToolTip(this.dtpStart , "日期只能都选或者都不选");
      }

      private void dtpEnd_MouseEnter(object sender, EventArgs e)
      {
         toolTip1.SetToolTip(this.dtpEnd , "日期只能都选或者都不选");
      }

你可能感兴趣的:(增加控件及注册绑定控件!)