简体   繁体   English

在其他datetimepicker winforms C#中,选择“日期”打开datetimepicker日历

[英]Open the calendar of datetimepicker on select of Date in other datetimepicker winforms C#

I have 3 Datetime pickers on a windows form in C#. 我在C#的Windows窗体上有3个Datetime选择器。 The datetimepickers are named dtp1,dtp2,dtp3. 日期时间选择器名为dtp1,dtp2,dtp3。 Once I select a date in dtp1 I want the calendar of dtp2 to open. 在dtp1中选择日期后,我希望打开dtp2的日历。 In other words dtp2 calendar should show up. 换句话说,应该显示dtp2日历。 I have searched in this forum and google but couldnt find right solution for this. 我在这个论坛和Google中进行了搜索,但是找不到正确的解决方案。

I am currently opening the calendar of dtp1 on value change of a combobox using the code below. 我目前正在使用以下代码在组合框的值更改时打开dtp1的日历。

dtp1.Select();
SendKeys.Send("%{DOWN}");

But if I use the same code on Value changed event of dtp1 it reopens the calendar of dtp1 instead of dtp2 . 但是,如果使用相同的代码上的价值变化的情况下dtp1它重新打开日历dtp1而非dtp2 I tried the following in value changed event of dtp1 . 我在dtp1值更改事件中尝试了以下dtp1

    private void dtp1_ValueChanged(object sender, EventArgs e)
    {
        listView1.Items.Clear();
        listView2.Items.Clear();

        dtp2.Select(); //dtp2.Focus();
        SendKeys.Send("%{DOWN}");
    }

My intention in opening the next calendar is to force the user to select the value from the next control. 我打开下一个日历的意图是迫使用户从下一个控件中选择值。 Any help would be appreciated. 任何帮助,将不胜感激。

Instead of ValueChanged event, use CloseUp 代替ValueChanged事件,使用CloseUp

private void dtp1_CloseUp(object sender, EventArgs e)
{
    this.dtp2.Select();
    SendKeys.Send("%{DOWN}");
}

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM