【问题标题】:How to set current date in active month using Pabo Calendar?如何使用 Pabo 日历设置活动月份的当前日期?
【发布时间】:2020-05-30 21:04:34
【问题描述】:

我想在 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; }

    }  
}

【问题讨论】:

    标签: c# winforms datetime calendar desktop-application


    【解决方案1】:

    我对@9​​87654321@ 控件不是很熟悉,但看起来您可以只更新从ActiveMonth 属性返回的对象的MonthYear 属性。像这样的东西应该可以工作:

    // 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 类的一个实例,它又包含两个属性YearMonth)。接下来,它将YearMonth 属性设置为所需的值。上面代码的更详细版本是:

    // 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 日历属性中设置日期,默认情况下它只读 {get;}
    • 顺便感谢您的回复 Maurits van Beusekom
    • 在这种情况下,您没有设置ActiveMonth 属性,而是读取它的值,然后更新或更改它的YearMonth 属性。
    • 好的先生,我的问题已经解决了,但我不知道是怎么回事:)
    • 你听从我的建议了吗?要我解释得更详细吗?顺便提一句。如果我的回答帮助您解决了问题,如果您将其标记为“已接受的答案”(通过单击复选标记符号),我将不胜感激。这有助于其他用户识别解决方案,并且我会获得一些 stackoverflow 积分奖励,这有助于我的声誉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 2021-06-15
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多