Error using System.Windows.Forms.SendKeys.Send ("% {DOWN}") [closed]

0

In a windows form application I have a DateTimePicker and I do not want it to display the date so I did the following:

public CadNovoPagamento()
{
    InitializeComponent();


    dtpEmissao.Value = DateTime.Now;
    dtpEmissao.Format = DateTimePickerFormat.Custom;
    dtpEmissao.CustomFormat = " ";
}

private void dtpEmissao_ValueChanged(object sender, EventArgs e)
{
    dtpEmissao.CustomFormat = "dd/MM/yyyy";
}

private void dtpEmissao_KeyPress(object sender, KeyPressEventArgs e)
{
    String teste = e.KeyChar.ToString();
    if (e.KeyChar == (char)Keys.Enter || teste == "\t")
    {
        dtpEmissao.Text = dtpEmissao.Value.ToString();
        System.Windows.Forms.SendKeys.Send("{TAB}");
    }
}
private void dtpEmissao_Enter(object sender, EventArgs e)
{
    System.Windows.Forms.SendKeys.Send("%{DOWN}");
}

private void dtpEmissao_Leave(object sender, EventArgs e)
{
    if (dtpVencimento.Text != "" && txtDias.Text != "")
    {
        DateTime datavencimento = Convert.ToDateTime(dtpVencimento.Text);
        DateTime dataemissao = Convert.ToDateTime(dtpEmissao.Text);
        //Instância do TimeSpan recebendo a subtração entre as datas
        TimeSpan ts = datavencimento.Subtract(dataemissao);

        txtDias.Text = ts.TotalDays.ToString();
    }
}

However, when it enters the dtpEmisson_Enter method the computer hangs and gets locked until the task manager is opened.

Does anyone know what might be happening?

An observation on a machine does not happen.

    
asked by anonymous 14.12.2017 / 11:58

1 answer

1

Without getting into the SendKeys issue, I think the resolution to your problem might be simpler:

Change the properties of your DateTimePicker:

    
14.12.2017 / 13:33