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

本文介绍如何在C#窗体应用程序中使用DateTimePicker控件,并展示了如何将其添加到工具栏,同时实现当鼠标悬停在日期选择器上时显示提示信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      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 , "日期只能都选或者都不选");
      }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值