-1

I am using visual studio c# to create a window form. The window form contains a Month Calendar.

I intend to highlight/bold only Saturday and Sunday (weekend) in my Calendar. How do I do this? because from the month calendar properties I only see dates but not days.

Natrah
  • 3
  • 1
  • Check this here: https://stackoverflow.com/questions/24962613/how-to-get-all-weekends-within-date-range-in-c-sharp Pass this to the BoldedDates of your calendar upon Form_Load() and/or month change or wherever you like. – LocEngineer Feb 05 '18 at 10:20

1 Answers1

0

you can achieve it this way :

public partial class Form1 : Form
{

 public Form1()
 {
    InitializeComponent();

    var weekends = GetDaysBetween(DateTime.Today.AddMonths(-1), DateTime.Today.AddMonths(12))
.Where(d => d.DayOfWeek == DayOfWeek.Saturday || d.DayOfWeek == DayOfWeek.Sunday).ToArray();

    monthCalendar1.RemoveAllBoldedDates();
    monthCalendar1.BoldedDates = weekends;
 }
IEnumerable<DateTime> GetDaysBetween(DateTime start, DateTime end)
 {
    for (DateTime i = start; i <= end; i = i.AddDays(1))
    {
        yield return i;
    }
 }

}

result screenshot

Xavave
  • 645
  • 11
  • 15
  • Thank you, Xavave. For those who are looking for a solution for this, yes, that piece of code works as expected. – Natrah Feb 06 '18 at 03:00