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
– Rovann Linhalis
your code is very strange. Because when instantiating the
form, puts the custom format as" "and then at the eventValueChangedyou set the custom format ?! Then in thekeypress, you define theTextcontrol being equal to yourvalue... and finally, you take theTextof the datetimepicker, converts toDateTime(hi?! ) to calculate a Timestamp– Rovann Linhalis
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.
– Tozzi
How could I do this "Show Checkbox" and/or the Maskedtextbox to no longer use this gambit?
– Tozzi
@Rovannlinhalis you know which Properties to bookmark?
– Tozzi
see the answer
– Rovann Linhalis