Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# and Month Calendar, selecting multiple dates

I am making a program that will help people "book" orders for a department in C#. They need to be able to choose multiple dates in different months.

I would prefer to have it so they can click a date, and then shift click another one to select all dates between those two, and control clicking as well, to do single selection/deselection. They have to be able to move between months while still retaining all the dates they clicked for the previous month, this way they can overview the dates they've selected to make it easier.

What is the best way to do this? Should I use Visual Studio's default month calendar or is there a more flexible one that exists?

like image 521
Napoli Avatar asked Nov 15 '09 21:11

Napoli


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is C full form?

Full form of C is “COMPILE”. One thing which was missing in C language was further added to C++ that is 'the concept of CLASSES'.


2 Answers

You can make it work by detecting clicks on dates and then add or remove the clicked date from the bolded dates. Implement the MonthCalendar's MouseDown event:

private void monthCalendar1_MouseDown(object sender, MouseEventArgs e) {
  MonthCalendar.HitTestInfo info = monthCalendar1.HitTest(e.Location);
  if (info.HitArea == MonthCalendar.HitArea.Date) {
    if (monthCalendar1.BoldedDates.Contains(info.Time))
      monthCalendar1.RemoveBoldedDate(info.Time);
    else 
      monthCalendar1.AddBoldedDate(info.Time);
    monthCalendar1.UpdateBoldedDates();
  }
}

Just one problem with this, it flickers like a cheap motel. No fix for that.

like image 92
Hans Passant Avatar answered Sep 22 '22 07:09

Hans Passant


The WinForms MonthCalendar supports selection of a Range, from Start to End but not the (de)selection of individual dates with Ctrl. So it seems it does not meet your requirements.

Just a quick note: If you resize the MonthCalendar it will show more months. Together with nobugz' answer that might give you a working solution.

like image 20
Henk Holterman Avatar answered Sep 22 '22 07:09

Henk Holterman