コード例 #1
0
ファイル: DatePicker.cs プロジェクト: sulerzh/DbExporter
      /// <summary>
      /// Disposes the control.
      /// </summary>
      /// <param name="disposing">true for releasing both managed and unmanaged resources, false for releasing only managed resources.</param>
      protected override void Dispose(bool disposing)
      {
         if (disposing)
         {
            if (this.dropDown != null)
            {
               this.dropDown.Closing -= this.DropDownClosing;
               this.dropDown.GotFocus -= this.FocusChanged;
               this.dropDown.LostFocus -= this.FocusChanged;
               this.dropDown.Dispose();
               this.dropDown = null;
            }

            this.monthCalendar.DateSelected -= this.MonthCalendarDateSelected;
            this.monthCalendar.InternalDateSelected -= this.MonthCalendarInternalDateSelected;
            this.monthCalendar.ActiveDateChanged -= this.MonthCalendarActiveDateChanged;
            this.monthCalendar.DateClicked -= this.MonthCalendarDateClicked;
            this.monthCalendar.GotFocus -= this.FocusChanged;
            this.monthCalendar.LostFocus -= this.FocusChanged;
            this.monthCalendar.MonthMenu.ItemClicked -= this.MenuItemClicked;
            this.monthCalendar.YearMenu.ItemClicked -= this.MenuItemClicked;
            this.monthCalendarHost.LostFocus -= this.MonthCalendarHostLostFocus;
            this.monthCalendarHost.GotFocus -= this.FocusChanged;

            this.monthCalendar.Dispose();

            this.monthCalendarHost.Dispose();

            this.dateTextBox.CheckDate -= this.DateTextBoxCheckDate;
            this.dateTextBox.GotFocus -= this.FocusChanged;
            this.dateTextBox.LostFocus -= this.FocusChanged;

            this.dateTextBox.Dispose();
         }

         base.Dispose(disposing);
      }
コード例 #2
0
ファイル: DatePicker.cs プロジェクト: sulerzh/DbExporter
      /// <summary>
      /// Initializes a new instance of the <see cref="DatePicker"/> class.
      /// </summary>
      public DatePicker()
      {
         this.SetStyle(
            ControlStyles.OptimizedDoubleBuffer
            | ControlStyles.AllPaintingInWmPaint
            | ControlStyles.UserPaint
            | ControlStyles.ResizeRedraw
            | ControlStyles.Selectable,
            true);

         this.borderColor = Color.FromArgb(127, 157, 185);
         this.focusedBorderColor = Color.Blue;

         this.Width = 101;
         this.Height = 22;
         this.AllowPromptAsInput = false;

         this.monthCalendar = new MonthCalendar
         {
            SelectionMode = MonthCalendarSelectionMode.Day
         };

         this.monthCalendar.KeyPress += this.MonthCalendarKeyPress;

         this.dateTextBox = new DatePickerDateTextBox(this)
         {
            Font = this.Font,
            Location = new Point(2, 2),
            Date = DateTime.Today,
            Width = this.Width - 19,
            Height = 18,
            MinDate = this.monthCalendar.MinDate,
            MaxDate = this.monthCalendar.MaxDate
         };

         this.dateTextBox.CheckDate += this.DateTextBoxCheckDate;
         this.dateTextBox.GotFocus += this.FocusChanged;
         this.dateTextBox.LostFocus += this.FocusChanged;

         this.Controls.Add(this.dateTextBox);

         this.monthCalendar.DateSelected += this.MonthCalendarDateSelected;
         this.monthCalendar.ActiveDateChanged += this.MonthCalendarActiveDateChanged;
         this.monthCalendar.DateClicked += this.MonthCalendarDateClicked;
         this.monthCalendar.InternalDateSelected += this.MonthCalendarInternalDateSelected;
         this.monthCalendar.GotFocus += this.FocusChanged;
         this.monthCalendar.LostFocus += this.FocusChanged;

         this.monthCalendarHost = new ToolStripControlHost(this.monthCalendar);
         this.monthCalendarHost.LostFocus += this.MonthCalendarHostLostFocus;
         this.monthCalendarHost.GotFocus += this.FocusChanged;

         this.dropDown = new CustomToolStripDropDown
          {
             DropShadowEnabled = true
          };

         this.dropDown.Closing += this.DropDownClosing;
         this.dropDown.GotFocus += this.FocusChanged;
         this.dropDown.LostFocus += this.FocusChanged;

         this.dropDown.Items.Add(this.monthCalendarHost);

         this.monthCalendar.MonthMenu.OwnerItem = this.monthCalendarHost;
         this.monthCalendar.YearMenu.OwnerItem = this.monthCalendarHost;

         this.monthCalendar.MonthMenu.ItemClicked += this.MenuItemClicked;
         this.monthCalendar.YearMenu.ItemClicked += this.MenuItemClicked;

         this.BackColor = SystemColors.Window;
         this.ClosePickerOnDayClick = true;
      }