Winforms Calendar code – C#
Filed in C#, Code Snippets on Sep.30, 2009
Here is a quick windows forms calendar code.
I used a TableLayoutPanel with Dock=Fill.
private void FillDays() { DateTime FirstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); int col = GetNumOfWeekDay(FirstDay.DayOfWeek); int row = 0; for (int i = 1; i < DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month)+1; i++, col++) { if (col > 6) { col = 0; row++; } Label lbl = new Label(); lbl.Text = i.ToString(); tlpCalendar.Controls.Add(lbl, col, row); } } private int GetNumOfWeekDay(DayOfWeek dow) { return (Int32)Enum.Parse(typeof(DayOfWeek), dow.ToString()); }
Related posts:























Leave a Reply
You must be logged in to post a comment.