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

Asked

Viewed 281 times

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 dtpEmissao_Enter method the computer crashes and stays locked until it opens the task manager.

Does anyone know what might be going on?

An observation on a machine the error does not happen.

  • a datetimepicker, and you do not want to display the date ?! explain better please

  • your code is very strange. Because when instantiating the form, puts the custom format as " " and then at the event ValueChanged you set the custom format ?! Then in the keypress, you define the Text control being equal to your value... and finally, you take the Text of the datetimepicker, converts to DateTime (hi?! ) to calculate a Timestamp

  • yes I need that when opening the screen the datetimepicker come like this //____ because this is not a mandatory field, so if I bring with me today’s date when recording it records with today’s date and necessarily is not today’s date.

  • How could I do this "Show Checkbox" and/or the Maskedtextbox to no longer use this gambit?

  • @Rovannlinhalis you know which Properties to bookmark?

  • see the answer

Show 1 more comment

1 answer

1


Without getting into the question of SendKeys, I think the solution to your problem may be simpler:

Change the properties of your Datetimepicker:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.