I am using the MonthCalendar control and want to disable saturday and sunday from being selected from the calendar.
Can anyone please suggest how to do this
Windows Forms Data Controls and Databinding
I am using the MonthCalendar control and want to disable saturday and sunday from being selected from the calendar.
Can anyone please suggest how to do this
Hi
The natural MonthCalendar control has not provide this functionality. But we can ingore mouse select and key select events. The following code shows how to do this.
public partial class MainForm : Form { public MainForm() { InitializeComponent(); MyMonthCalendar mc = new MyMonthCalendar(); this.Controls.Add(mc); } } public class MyMonthCalendar : MonthCalendar { protected override void WndProc(ref Message m) { if (m.Msg == WM_LBUTTONDOWN) { int x = LOWORD((int)m.LParam); int y = HIWORD((int)m.LParam); HitTestInfo info = HitTest(x, y); if (info.HitArea == HitArea.Date && (info.Time.DayOfWeek == DayOfWeek.Saturday || info.Time.DayOfWeek == DayOfWeek.Sunday)) return; } base.WndProc(ref m); } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { return true; } private static int HIWORD(int n) { return ((n >> 0x10) & 0xffff); } private static int LOWORD(int n) { return (n & 0xffff); } private const int WM_LBUTTONDOWN = 0x0201; }
Best Regards,
Wei Zhou