示例#1
0
        /// <summary>
        /// EditValue is inherited from UITypeEditor, it is used to create, place and
        /// show the HourMinuteSelectorForm on the screen.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns>The TimeSpan selected by the user</returns>
        public override Object EditValue(ITypeDescriptorContext context,
                                         IServiceProvider provider,
                                         Object value)
        {
            if (context != null &&
                context.Instance != null &&
                provider != null)
            {
                m_oEditorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                if (m_oEditorService != null)
                {
                    m_oHourMinuteForm          = new HourMinuteSelectorForm();
                    m_oHourMinuteForm.Size     = new Size(346, 135);
                    m_oHourMinuteForm.Location = CalculateLocation(m_oHourMinuteForm.Size);

                    m_oHourMinuteForm.SelectedTime = (TimeSpan)value;

                    m_oEditorService.ShowDialog(m_oHourMinuteForm);

                    value = m_oHourMinuteForm.SelectedTime;
                }
            }

            return(value);
        }
示例#2
0
        /// <summary>
        /// Constructor that initialize its private data members.
        /// </summary>
        public TimePicker()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            m_oHourMinuteForm             = new HourMinuteSelectorForm();
            m_oHourMinuteForm.Size        = new Size(346, 135);
            m_oHourMinuteForm.Deactivate += new EventHandler(m_oHourMinuteForm_Deactivate);

            m_oHourForm             = new HourSelectorForm();
            m_oHourForm.Size        = new Size(292, 47);
            m_oHourForm.Deactivate += new EventHandler(m_oHourForm_Deactivate);

            m_oMinuteForm             = new MinuteSelectorForm();
            m_oMinuteForm.Size        = new Size(242, 146);
            m_oMinuteForm.Deactivate += new EventHandler(m_oMinuteForm_Deactivate);

            // If you want these properties to work in the designer,
            // you have to set their default values here.  There is
            // something wrong with the DefaultValue attribute
            // Also put them after the creation of the forms since
            // they set some properties in these forms.
            ButtonColor    = System.Drawing.SystemColors.Control;
            SelectedColor  = Color.White;
            SeparatorColor = Color.RosyBrown;
            TimeSelector   = TimePickerFormat.HoursAndMinutes;
            Format         = "HH:MM";
            TimeSpan l_sTime = DateTime.Now.TimeOfDay;

            Value        = new TimeSpan(l_sTime.Hours, l_sTime.Minutes, 0);
            ShowDropDown = true;
            ShowCheckBox = false;
            RightToLeft  = RightToLeft.No;
        }