コード例 #1
0
        // EditValue is inherited from UITypeEditor, it is used to create, place and
        // show the HourMinuteSelectorForm on the screen.
        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.Location = CalculateLocation(m_oHourMinuteForm.Size);
                    m_oHourMinuteForm.Font     = new Font("Microsoft Sans Serif", 10.25F, FontStyle.Regular,
                                                          GraphicsUnit.Point, ((0)));

                    m_oHourMinuteForm.SelectedTime = (TimeSpan)value;

                    m_oEditorService.ShowDialog(m_oHourMinuteForm);

                    value = m_oHourMinuteForm.SelectedTime;
                }
            }

            return(value);
        }
コード例 #2
0
        public TimePicker()
        {
            InitializeComponent();

            m_oHourMinuteForm                 = new HourMinuteSelectorForm();
            m_oHourMinuteForm.Size            = new Size(346 + 2, 135 + 21);
            m_oHourMinuteForm.KeyToHidePicker = Keys.Escape;
            m_oHourMinuteForm.Deactivate     += m_oHourMinuteForm_Deactivate;

            m_oHourForm                 = new HourSelectorForm();
            m_oHourForm.Size            = new Size(292, 47);
            m_oHourForm.KeyToHidePicker = Keys.Escape;
            m_oHourForm.Deactivate     += m_oHourForm_Deactivate;

            m_oMinuteForm                 = new MinuteSelectorForm();
            m_oMinuteForm.Size            = new Size(242, 146);
            m_oMinuteForm.KeyToHidePicker = Keys.Escape;
            m_oMinuteForm.Deactivate     += 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           = SystemColors.Control;
            SelectedColor         = SystemColors.Highlight;
            SeparatorColor        = SystemColors.AppWorkspace;
            TimeSelector          = TimePickerFormat.HoursAndMinutes;
            m_cSeparator          = SEPARATOR;
            m_szSeparatorAsString = new String(new[]
            {
                SEPARATOR
            });
            Format = "HH:MM";
            TimeSpan _lSTime = DateTime.Now.TimeOfDay;

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