0

我的代码有问题...初始化日期时间时看不到消息框。代码有什么问题?我根本找不到任何错误。我正在使用支持 DateTimePicker 的 WPF 修改应用程序。它看起来像这样:

    private void Start_Click(object sender, RoutedEventArgs e)
    {
        startjob();
    }
    private void startjob()
    {
        DateTime start = (DateTime)DateTimePicker1.Value;
        DateTime end = (DateTime)DateTimePicker2.Value;
        DateTime now = DateTime.Now;
        if ((now > start) && (now < end))
        {
            System.Windows.MessageBox.Show("It works");
        }

XAML:
<wpfTool:DateTimePicker x:Name="DateTimePicker1" Margin="506,189,192,1137" Width="227" TimeFormat="LongTime">
                </wpfTool:DateTimePicker>
                <wpfTool:DateTimePicker x:Name="DateTimePicker2" Margin="506,238,192,1088" Width="227" Height="25">
                    </wpfTool:DateTimePicker>
4

1 回答 1

2
DateTime? start = DateTimePicker1.Value;
DateTime? end = DateTimePicker2.Value;
DateTime now = DateTime.Now;

if (start == null || end == null)
{
    // one of the pickers is empty
}
else if (now >= start.Value && now <= end.Value)
{
    // you selected values in range of "now"
}
于 2013-04-14T01:07:51.557 回答