-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormCalendar.cs
More file actions
170 lines (144 loc) Β· 6.29 KB
/
FormCalendar.cs
File metadata and controls
170 lines (144 loc) Β· 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace FormNoticeBoardAndCalendar
{
public class FormCalendar : Form
{
private TableLayoutPanel calendarTable;
private Dictionary<DateTime, FlowLayoutPanel> datePanels = new Dictionary<DateTime, FlowLayoutPanel>();
private DateTime currentMonth = DateTime.Today;
public FormCalendar()
{
InitializeComponent();
CreateCalendar(currentMonth);
}
private void InitializeComponent()
{
this.Text = "π
μΊλ¦°λ";
this.ClientSize = new Size(1000, 800);
this.StartPosition = FormStartPosition.CenterScreen;
this.BackColor = Color.FromArgb(245,240,255);
this.Font = new Font("Noto Sans KR", 10, FontStyle.Regular);
calendarTable = new TableLayoutPanel
{
RowCount = 6,
ColumnCount = 7,
Dock = DockStyle.Fill,
CellBorderStyle = TableLayoutPanelCellBorderStyle.Single,
Padding = new Padding(5),
BackColor = Color.White
};
for (int i = 0; i < 7; i++)
calendarTable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f / 7));
for (int i = 0; i < 6; i++)
calendarTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100f / 6));
this.Controls.Add(calendarTable);
}
private void CreateCalendar(DateTime month)
{
calendarTable.Controls.Clear();
datePanels.Clear();
DateTime firstDay = new DateTime(month.Year, month.Month, 1);
int startDayOfWeek = (int)firstDay.DayOfWeek;
int daysInMonth = DateTime.DaysInMonth(month.Year, month.Month);
// νμν ν κ³μ°
int totalCells = startDayOfWeek + daysInMonth;
int requiredRows = (int)Math.Ceiling(totalCells / 7.0);
calendarTable.RowCount = requiredRows;
calendarTable.RowStyles.Clear();
for (int i = 0; i < requiredRows; i++)
{
calendarTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100f / requiredRows));
}
int dayCounter = 1;
for (int row = 0; row < requiredRows; row++)
{
for (int col = 0; col < 7; col++)
{
Panel dayPanel = new Panel();
dayPanel.Dock = DockStyle.Fill;
dayPanel.BorderStyle = BorderStyle.FixedSingle;
dayPanel.BackColor = Color.WhiteSmoke;
if (row == 0 && col < startDayOfWeek)
{
calendarTable.Controls.Add(dayPanel, col, row);
continue;
}
if (dayCounter > daysInMonth)
{
calendarTable.Controls.Add(dayPanel, col, row);
continue;
}
DateTime currentDate = new DateTime(month.Year, month.Month, dayCounter);
Label dayLabel = new Label();
dayLabel.Text = dayCounter.ToString();
dayLabel.Dock = DockStyle.Top;
dayLabel.TextAlign = ContentAlignment.TopRight;
dayLabel.Padding = new Padding(0, 0, 5, 0);
dayLabel.Font = new Font("Segoe UI Semibold", 12);
dayLabel.ForeColor = Color.FromArgb(60, 60, 60);
FlowLayoutPanel noticePanel = new FlowLayoutPanel();
noticePanel.Dock = DockStyle.Fill;
noticePanel.FlowDirection = FlowDirection.TopDown;
noticePanel.WrapContents = false;
noticePanel.AutoScroll = true;
noticePanel.Padding = new Padding(3);
dayPanel.Controls.Add(noticePanel);
dayPanel.Controls.Add(dayLabel);
calendarTable.Controls.Add(dayPanel, col, row);
datePanels[currentDate] = noticePanel;
dayCounter++;
}
}
}
public void SetNotices(List<NoticeSimple> notices)
{
foreach (var flowPanel in datePanels.Values)
{
flowPanel.Controls.Clear();
}
foreach (var notice in notices)
{
SetNoticeButton(notice.ScheduleDate.Date, notice);
}
}
private void SetNoticeButton(DateTime date, NoticeSimple notice)
{
if (!datePanels.ContainsKey(date))
return;
var flowPanel = datePanels[date];
Button btn = new Button
{
Text = notice.Title.Length > 12 ? notice.Title.Substring(0, 12) + "..." : notice.Title,
AutoSize = false,
Width = flowPanel.ClientSize.Width - 10,
Height = 35,
BackColor = Color.FromArgb(91, 155, 213), // DodgerBlue κ³μ΄, μμν νλμ
ForeColor = Color.White,
Font = new Font("Segoe UI", 9, FontStyle.Bold),
FlatStyle = FlatStyle.Flat,
Margin = new Padding(3, 2, 3, 2),
Cursor = Cursors.Hand,
TextAlign = ContentAlignment.MiddleCenter,
Padding = new Padding(6, 0, 6, 0)
};
btn.FlatAppearance.BorderSize = 0;
btn.FlatAppearance.MouseOverBackColor = Color.FromArgb(41, 128, 185);
btn.FlatAppearance.MouseDownBackColor = Color.FromArgb(31, 97, 141);
btn.Padding = new Padding(5, 0, 5, 0);
btn.Click += (s, e) =>
{
FormDetailNotice detailForm = new FormDetailNotice(
notice.Title,
notice.Author,
notice.WriteDate,
notice.Content
);
detailForm.ShowDialog();
};
flowPanel.Controls.Add(btn);
}
}
}