Show user-selected date using Monthcalendar

Asked

Viewed 40 times

2

I need that when a user selects a date a Messagebox appears saying:

Your class has been scheduled for [date]

private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
     MessageBox.Show("Proxima Aula Maracada para: " + sender);
     // Eu coloquei esse comando pois ele aparece o que eu quero 
     // porém aparece mais coisas que eu não quero
}
  • Does the answer meet your request? You need more details?

1 answer

2


If you’re wearing one MonthCalendar, could do the following:

private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
    var data = ((MonthCalendar)sender).SelectionStart.ToShortDateString(); 
    MessageBox.Show("Proxima Aula Maracada para: " + data);
}

Note that the method ToShortDateString() serves to return the representation of the date in string in short format depending on the culture, in the case of pt-BR would dd/MM/yyyy.

It would also be possible to use the event arguments:

private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
    MessageBox.Show("Proxima Aula Maracada para: " + e.Start.ToShortDateString);
}
  • +1 Thank you LINQ Thank you

Browser other questions tagged

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