Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 同步MonthCalendar和Datetimepicker_C#_Winforms_Visual Studio 2010_Datetimepicker_Monthcalendar - Fatal编程技术网

C# 同步MonthCalendar和Datetimepicker

C# 同步MonthCalendar和Datetimepicker,c#,winforms,visual-studio-2010,datetimepicker,monthcalendar,C#,Winforms,Visual Studio 2010,Datetimepicker,Monthcalendar,我在表单中有一个MonthCalendar和一个日期时间选择器。有没有办法同步它们?换句话说,当我更改MonthCalendar的日期时,DateTimePicker的日期将自动等于该日期,反之亦然。 我在下面试过了,但都不行 datetimePicker1 = monthCalendar1.SelectionRange.ToString("dd MMMM yyyy hh :mm"); monthCalendar1 = datetimePicker1.Value.ToOADate(); 只需

我在表单中有一个MonthCalendar和一个日期时间选择器。有没有办法同步它们?换句话说,当我更改MonthCalendar的日期时,DateTimePicker的日期将自动等于该日期,反之亦然。 我在下面试过了,但都不行

datetimePicker1 = monthCalendar1.SelectionRange.ToString("dd MMMM yyyy  hh :mm");
monthCalendar1 = datetimePicker1.Value.ToOADate();

只需使用这些控件的默认事件就可以让一个控件更新另一个控件。双击控件以添加事件处理程序,并使其如下所示:

    private void dateTimePicker1_ValueChanged(object sender, EventArgs e) {
        monthCalendar1.SetDate(dateTimePicker1.Value);
    }

    private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e) {
        dateTimePicker1.Value = monthCalendar1.SelectionStart;
    }

请注意,DateTimePicker已经内置了MonthCalendar,您可以在单击下拉按钮时获得它。这是它的典型使用方式,它们已经同步。

您的
月日历1
是否有一些属性,如
日期
,类型为
日期时间
?顺便说一句,它是否有一个
数据绑定
?@KingKing它是Visual Studio提供的默认monthCalendar,我认为它没有这些属性。这正是我想要的。是的,我被告知这一点,但在这个项目中,出于某些原因,我想两者兼而有之。非常感谢。