void l_click(object sender, EventArgs e) { DateTimeButton dtb = (sender as DateTimeButton); if (_selectedDateTimeButton != dtb) { _colorBeforeSelection = dtb.StandardColor; dtb.BackColor = Color.LightBlue; _selectedDate = DateTime.Parse(dtb.Name); if (_selectedDateTimeButton != null) { _selectedDateTimeButton.BackColor = _selectedDateTimeButton.StandardColor; } _selectedDateTimeButton = dtb; if (onDaySelected != null) { onDaySelected(this, new DaySelectedEventArgs(DateTime.Parse((sender as DateTimeButton).Name))); } SelectedDate = DateTime.Parse((sender as DateTimeButton).Name); } }
void l_Enter(object sender, EventArgs e) { if (_selectedDateTimeButton != (sender as DateTimeButton)) { _lastEntered = (sender as DateTimeButton); _lastEnteredColor = (sender as DateTimeButton).BackColor; (sender as DateTimeButton).BackColor = Color.Blue; } }
void l_Paint(object sender, PaintEventArgs e) { DateTimeButton dtb = (sender as DateTimeButton); if (dtb.Name.StartsWith("WeekDay")) { e.Graphics.DrawLine(Pens.Black, new Point(0, dtb.Height - 1), new Point(dtb.Width, dtb.Height - 1)); } else if (dtb.Name.StartsWith("WeekNumber")) { dtb.BackColor = Color.LightGray; } }
private List <DateTimeButton> GenerateDtbCollection(int Month, int Year) { DateTime MonthToFill = new DateTime(Year, Month, 1); int[] weeks = GetActual4WeeksOfYear(MonthToFill); int blank = GetBlankTrailingDays(MonthToFill); int monthlengt = DateTime.DaysInMonth(Year, Month); List <DateTimeButton> lbs = new List <DateTimeButton>(); lbs.Add(new DateTimeButton()); DateTimeButton mo = new DateTimeButton(); mo.Text = "Mo"; mo.Name = "WeekDay1"; DateTimeButton di = new DateTimeButton(); di.Text = "Di"; di.Name = "WeekDay2"; DateTimeButton mi = new DateTimeButton(); mi.Text = "Mi"; mi.Name = "WeekDay3"; DateTimeButton Do = new DateTimeButton(); Do.Text = "Do"; Do.Name = "WeekDay4"; DateTimeButton fr = new DateTimeButton(); fr.Text = "Fr"; fr.Name = "WeekDay5"; DateTimeButton sa = new DateTimeButton(); sa.Text = "Sa"; sa.Name = "WeekDay6"; DateTimeButton so = new DateTimeButton(); so.Text = "So"; so.Name = "WeekDay7"; string MonthStr = Month.ToString(); if (MonthStr.Length == 1) { MonthStr = "0" + MonthStr; } if (blank >= 7) { blank = 0; } for (int i = 0; i <= monthlengt - 1; i++) { DateTimeButton day = new DateTimeButton(); day.Text = (i + 1).ToString(); string name = (i + 1).ToString(); name = name.Length == 1 ? "0" + name : name; day.Name = name + "." + MonthStr + "." + Year; lbs.Add(day); } lbs.InsertRange(1, new DateTimeButton[] { mo, di, mi, Do, fr, sa, so }); for (int i = 0; i <= blank - 1; i++) { DateTimeButton blankL = new DateTimeButton(); blankL.Text = " "; blankL.Name = "blank" + i.ToString(); lbs.Insert(i + 8, blankL); } int z = 0; for (int i = 0; i <= 5; i++) { z += 8; DateTimeButton dtb = new DateTimeButton(); dtb.Text = weeks[i].ToString(); dtb.Name = "WeekNumber" + weeks[i].ToString(); if (lbs.Count > z) { lbs.Insert(z, dtb); } } int x = 3; int y = 8; foreach (DateTimeButton l in lbs) { l.Margin = new Padding(0); l.MinimumSize = new System.Drawing.Size(25, 15); l.MaximumSize = new System.Drawing.Size(25, 15); l.Location = new Point(x, y); l.Paint += new PaintEventHandler(l_Paint); l.TextAlign = ContentAlignment.MiddleCenter; l.BorderStyle = System.Windows.Forms.BorderStyle.None; x += 25; if (x == ((8 * 25) + 3)) { y += 15; x = 3; } if (l.Name.Contains(".")) { DateTime dt = DateTime.Parse(l.Name); if (_markedDates.ContainsKey(dt)) { l.BackColor = _markedDates[dt]; l.StandardColor = _markedDates[dt]; } if (dt.ToShortDateString() == DateTime.Now.ToShortDateString()) { l.BorderStyle = BorderStyle.FixedSingle; } //if (l.Name == _selectedDate.ToShortDateString()) // l.BackColor = _selectedDateColor; l.MouseEnter += new EventHandler(l_Enter); l.MouseLeave += new EventHandler(l_MouseLeave); l.Click += new EventHandler(l_click); } } return(lbs); }