public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(string))
     {
         // cast value to ActiveMonth
         NuGenActiveMonth dest = (NuGenActiveMonth)value;
         // create property string
         return(dest.Calendar.MonthName(dest.Month) + "; " + dest.Year);
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
 public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
 {
     if (value.GetType() == typeof(string))
     {
         NuGenActiveMonth m = (NuGenActiveMonth)context.Instance;
         if (m.Calendar.IsYearValid(value.ToString()))
         {
             return(Convert.ToInt32(value));
         }
     }
     return(base.ConvertFrom(context, culture, value));
 }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            int ret = 0;

            if (value.GetType() == typeof(string))
            {
                NuGenActiveMonth m = (NuGenActiveMonth)context.Instance;
                ret = m.Calendar.MonthNumber(value.ToString());
                if ((ret >= 1) && (ret <= 12))
                {
                    return(ret);
                }
            }
            return(base.ConvertFrom(context, culture, value));
        }
        GetStandardValues(ITypeDescriptorContext context)
        {
            NuGenActiveMonth m = (NuGenActiveMonth)context.Instance;

            return(new StandardValuesCollection(m.Calendar.AllowedMonths()));
        }
Пример #5
0
		/// <summary>
		/// Initializes a new instance of the <see cref="NuGenCalendar"/> class.
		/// </summary>
		/// <param name="serviceProvider">
		/// <para>Requires:</para>
		/// <para><see cref="INuGenControlStateService"/></para>
		/// <para><see cref="INuGenCalendarRenderer"/></para>
		/// </param>
		public NuGenCalendar(INuGenServiceProvider serviceProvider)
			: base(serviceProvider)
		{
			this.SetStyle(ControlStyles.DoubleBuffer, true);
			this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			this.SetStyle(ControlStyles.UserPaint, true);
			this.SetStyle(ControlStyles.ResizeRedraw, true);
			this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

			_borderColor = Color.Black;
			_selectButton = MouseButtons.Left;
			_extendedKey = NuGenExtendedSelectionKey.Ctrl;

			_activeRegion = NuGenCalendarRegion.None;
			_selectionMode = NuGenSelectionMode.MultiSimple;
			_dateTimeFormat = DateTimeFormatInfo.CurrentInfo;
			_theme = IntPtr.Zero;

			_installedCultures = CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures);
			_culture = CultureInfo.CurrentCulture;

			_showToday = true;
			_showTrailing = true;
			_showFocus = true;
			_todayColor = Color.Red;
			//initiate regions	
			_weekday = new NuGenWeekday(this);
			_month = new NuGenMonth(this);
			_footer = new NuGenFooter(this);
			_weeknumber = new NuGenWeeknumber(this);
			_header = new NuGenHeader(this, serviceProvider);

			_keyboard = new KeyboardConfig(this);
			_keyboardEnabled = true;
			_activeMonth = new NuGenActiveMonth(this);
			_dateItemCollection = new NuGenDateItemCollection(this);
			_selectedDates = new NuGenSelectedDatesCollection(this);

			// setup callback for weeknumbers
			WeeknumberCallBack = new NuGenWeekCallback(_weeknumber.CalcWeek);

			// setup internal events
			_hook.KeyDown += new KeyEventHandler(m_hook_KeyDown);
			_hook.KeyUp += new KeyEventHandler(m_hook_KeyUp);

			_dateItemCollection.DateItemModified += m_dateItemCollection_DateItemModified;

			_month.DayRender += m_month_DayRender;
			_month.DayQueryInfo += m_month_DayQueryInfo;
			_month.DayLostFocus += m_month_DayLostFocus;
			_month.DayGotFocus += m_month_DayGotFocus;
			_month.ImageClick += m_month_ImageClick;
			_month.DayMouseMove += m_month_DayMouseMove;
			_month.DayClick += m_month_DayClick;
			_month.DayDoubleClick += m_month_DayDoubleClick;
			_month.DaySelected += m_month_DaySelected;
			_month.DayDeselected += m_month_DayDeselected;
			_month.ColorChanged += m_month_ColorChanged;
			_month.BorderStyleChanged += m_month_BorderStyleChanged;
			_month.PropertyChanged += m_month_PropertyChanged;
			_month.BeforeDaySelected += m_month_BeforeDaySelected;
			_month.BeforeDayDeselected += m_month_BeforeDayDeselected;

			_footer.Click += m_footer_Click;
			_footer.DoubleClick += m_footer_DoubleClick;
			_footer.PropertyChanged += m_footer_PropertyChanged;

			_weeknumber.PropertyChanged += m_weeknumber_PropertyChanged;
			_weeknumber.Click += m_weeknumber_Click;
			_weeknumber.DoubleClick += m_weeknumber_DoubleClick;

			_weekday.PropertyChanged += m_weekday_PropertyChanged;
			_weekday.Click += m_weekday_Click;
			_weekday.DoubleClick += m_weekday_DoubleClick;

			_header.PropertyChanged += m_header_PropertyChanged;
			_header.Click += m_header_Click;
			_header.DoubleClick += m_header_DoubleClick;
			_header.PrevMonthButtonClick += m_header_PrevMonthButtonClick;
			_header.NextMonthButtonClick += m_header_NextMonthButtonClick;
			_header.PrevYearButtonClick += m_header_PrevYearButtonClick;
			_header.NextYearButtonClick += m_header_NextYearButtonClick;


			_activeMonth.MonthChanged += m_activeMonth_MonthChanged;
			_activeMonth.BeforeMonthChanged += m_activeMonth_BeforeMonthChanged;

			_printDoc.BeginPrint += m_printDoc_BeginPrint;
			_printDoc.PrintPage += m_printDoc_PrintPage;
			_printDoc.QueryPageSettings += m_printDoc_QueryPageSettings;

			_borderStyle = ButtonBorderStyle.Solid;

			_printDoc.DocumentName = "MonthCalendar";

			_showFooter = true;
			_showHeader = true;
			_showWeekday = true;

			_selectTrailing = true;
			_selectKeyDown = false;

			_activeMonth.Month = DateTime.Today.Month;
			_activeMonth.Year = DateTime.Today.Year;

			_minDate = DateTime.Now.AddYears(-10);
			_maxDate = DateTime.Now.AddYears(10);

			_month.SelectedMonth = DateTime.Parse(_activeMonth.Year + "-" + _activeMonth.Month + "-01");

			_hook.InstallKeyboardHook();
			_keyHandled = false;
			this.Size = new Size(250, 250);
			Setup();
			this.UseTheme = true;
		}