C# 如何使用Pabo日历设置活动月份中的当前日期?

C# 如何使用Pabo日历设置活动月份中的当前日期?,c#,winforms,datetime,calendar,desktop-application,C#,Winforms,Datetime,Calendar,Desktop Application,我想在Pabo日历中显示当前日期,但只有一个只读属性 如何设置当前日期 namespace Pabo.Calendar { [DefaultEvent("MonthChanged")] [DefaultProperty("Name")] [Designer(typeof(MonthCalendarDesigner))] [ToolboxBitmap(typeof(MonthCalendar), "Pabo.Calendar.MonthCalendar.bmp")]

我想在Pabo日历中显示当前日期,但只有一个只读属性

如何设置当前日期

namespace Pabo.Calendar
{
    [DefaultEvent("MonthChanged")]
    [DefaultProperty("Name")]
    [Designer(typeof(MonthCalendarDesigner))]
    [ToolboxBitmap(typeof(MonthCalendar), "Pabo.Calendar.MonthCalendar.bmp")]
    [ToolboxItem(true)]
    public class MonthCalendar : Control
    {
        public WeekCallBack WeeknumberCallBack;

        public MonthCalendar();

        [Category("Behavior")]
        [Description("")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ActiveMonth ActiveMonth { get; }
        [Category("Behavior")]
        [DefaultValue(0)]
        [Description("First day of week.")]
        [RefreshProperties(RefreshProperties.All)]
        [TypeConverter(typeof(FirstDayOfWeekConverter))]
        public int FirstDayOfWeek { get; set; }

    }  
}

我不太熟悉
Pabo.Calendar
控件,但它看起来可以只更新从
ActiveMonth
属性返回的对象的
Month
Year
属性。像这样的方法应该会奏效:

// This code example assumes you have an instance of the 
// MonthCalendar object that is called `myMonthCalendar`.
var today = DateTime.Today;
myMonthCalendar.ActiveMonth.Year = today.Year;
myMonthCalendar.ActiveMonth.Month = today.Month;
上面的代码从
ActiveMonth
属性读取值(这是
ActiveMonth
类的一个实例,它依次包含两个属性
Year
Month
)。接下来,它将
属性设置为所需的值。上述代码的更详细版本是:

// This code example assumes you have an instance of the 
// MonthCalendar object that is called `myMonthCalendar`.
var today = DateTime.Today;
var activeMonth = myMonthCalendar.ActiveMonth; // Here we only read the ActiveMonth property.
activeMonth.Year = today.Year; // Here we update or set the Year value
activeMonth.Month = today.Month; // Here we update or set the Month value

我不太熟悉
Pabo.Calendar
控件,但它看起来可以只更新从
ActiveMonth
属性返回的对象的
Month
Year
属性。像这样的方法应该会奏效:

// This code example assumes you have an instance of the 
// MonthCalendar object that is called `myMonthCalendar`.
var today = DateTime.Today;
myMonthCalendar.ActiveMonth.Year = today.Year;
myMonthCalendar.ActiveMonth.Month = today.Month;
上面的代码从
ActiveMonth
属性读取值(这是
ActiveMonth
类的一个实例,它依次包含两个属性
Year
Month
)。接下来,它将
属性设置为所需的值。上述代码的更详细版本是:

// This code example assumes you have an instance of the 
// MonthCalendar object that is called `myMonthCalendar`.
var today = DateTime.Today;
var activeMonth = myMonthCalendar.ActiveMonth; // Here we only read the ActiveMonth property.
activeMonth.Year = today.Year; // Here we update or set the Year value
activeMonth.Month = today.Month; // Here we update or set the Month value

但是我无法在pabo calendar属性中设置日期默认为只读{get;}顺便说一句,非常感谢您的回复Maurits van Beusekom在这种情况下,您没有设置
ActiveMonth
属性,您正在读取它的值,然后更新或更改它的
Year
Month
属性。好的先生,我的问题已经解决了,但我不知道是怎么回事:)你听从我的建议了吗?你想让我更详细地解释一下吗?B.t.w.如果我的答案帮助您解决了问题,如果您将其标记为“已接受答案”(单击复选标记符号),我将不胜感激。这有助于其他用户识别解决方案,我获得了一些stackoverflow积分,这有助于提高我的声誉。但我无法在pabo calendar属性中设置日期,默认为只读{get;}顺便说一句,非常感谢您的回复毛里茨·范·伯塞科姆在这种情况下,您没有设置
ActiveMonth
属性,您正在读取它的值,然后更新或更改它的
属性。好的,先生,我的问题已经解决,但我不知道它是如何发生的:)您遵循我的建议了吗?你想让我更详细地解释一下吗?B.t.w.如果我的答案帮助您解决了问题,如果您将其标记为“已接受答案”(单击复选标记符号),我将不胜感激。这有助于其他用户识别解决方案,我还获得了一些stackoverflow积分,这有助于提高我的声誉。