前提・実現したいこと
Visual Studio2017のVB.NETでカレンダーを制作しております。
現在の日にちに印またはパネルの色を変えたいです。
また日にちをクリックすると別ページのForm1に画面遷移させたです。
利用環境:Visual Studio2017
WindowsFormで作成しています。
こちらが現在のソースコードになります。
VB.NET
1 2Public Class Form2 3 '-------------------------------------------------------------------------------------------------------- 4 '今日の日付・曜日を取得する 5 '-------------------------------------------------------------------------------------------------------- 6 Private listF1Day As New List(Of FlowLayoutPanel) 7 Private currentDate As DateTime = DateTime.Today 8 '-------------------------------------------------------------------------------------------------------- 9 'Panelの設定 10 '-------------------------------------------------------------------------------------------------------- 11 Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load 12 GenerateDayPanel(42) 13 DisplayCurrentDate() 14 End Sub 15 '-------------------------------------------------------------------------------------------------------- 16 '月初めの日にちの設定 17 '-------------------------------------------------------------------------------------------------------- 18 Private Function GetFirstDayOfWeekOfCurrentDate() As Integer 19 Dim firstDayOfMonth As DateTime = New Date(currentDate.Year, currentDate.Month, 1) 20 Return firstDayOfMonth.DayOfWeek + 1 21 End Function 22 '-------------------------------------------------------------------------------------------------------- 23 '月終わりの日にちの設定 24 '-------------------------------------------------------------------------------------------------------- 25 Private Function GetTotalDaysOfCurrentDate() As Integer 26 Dim firstDayOfCurrentDate As DateTime = New Date(currentDate.Year, currentDate.Month, 1) 27 Return firstDayOfCurrentDate.AddMonths(1).AddDays(-1).Day 28 End Function 29 '-------------------------------------------------------------------------------------------------------- 30 '左上年月設定 31 '-------------------------------------------------------------------------------------------------------- 32 Private Sub DisplayCurrentDate() 33 lblMonth.Text = currentDate.ToString("yyyy.MMMM") 34 Addlabel1DayToF1Day(GetFirstDayOfWeekOfCurrentDate(), GetTotalDaysOfCurrentDate()) 35 End Sub 36 '-------------------------------------------------------------------------------------------------------- 37 '右上ボタン 38 '-------------------------------------------------------------------------------------------------------- 39 Private Sub PrevMonth() 40 currentDate = currentDate.AddMonths(-1) 41 DisplayCurrentDate() 42 End Sub 43 44 Private Sub NextMonth() 45 currentDate = currentDate.AddMonths(1) 46 DisplayCurrentDate() 47 End Sub 48 49 Private Sub Today() 50 currentDate = DateTime.Today 51 DisplayCurrentDate() 52 End Sub 53 '-------------------------------------------------------------------------------------------------------- 54 '日付のPanel設定 55 '-------------------------------------------------------------------------------------------------------- 56 Private Sub GenerateDayPanel(ByVal totalDays As Integer) 57 f1Days.Controls.Clear() 58 listF1Day.Clear() 59 60 For i As Integer = 1 To totalDays 61 Dim f1 As New FlowLayoutPanel 62 f1.Name = $"f1Day{i}" 63 f1.Size = New Size(144, 79) 64 f1.BackColor = Color.White 65 f1Days.Controls.Add(f1) 66 f1.BorderStyle = BorderStyle.FixedSingle 67 listF1Day.Add(f1) 68 Next 69 End Sub 70 '-------------------------------------------------------------------------------------------------------- 71 '日付Panelの日にち設定 72 '-------------------------------------------------------------------------------------------------------- 73 Private Sub Addlabel1DayToF1Day(ByVal startDayAtF1Number As Integer, ByVal totalDaysInMonth As Integer) 74 For Each f1 As FlowLayoutPanel In listF1Day 75 f1.Controls.Clear() 76 Next 77 78 For i As Integer = 1 To totalDaysInMonth 79 Dim lbl As New Label 80 lbl.Name = $"lblDay{i}" 81 lbl.AutoSize = False 82 lbl.TextAlign = ContentAlignment.MiddleRight 83 lbl.Size = New Size(122, 22) 84 lbl.Text = i 85 lbl.Font = New Font("Microsoft Sans Serif", 12) 86 listF1Day((i - 1) + (startDayAtF1Number - 1)).Controls.Add(lbl) 87 Next 88 End Sub 89 '-------------------------------------------------------------------------------------------------------- 90 'ボタンの設定 91 '-------------------------------------------------------------------------------------------------------- 92 Private Sub btnPrevMonth_Click(sender As Object, e As EventArgs) Handles btnPrevMonth.Click 93 PrevMonth() 94 End Sub 95 96 Private Sub btnNextMonth_Click(sender As Object, e As EventArgs) Handles btnNextMonth.Click 97 NextMonth() 98 End Sub 99 100 Private Sub btnToday_Click(sender As Object, e As EventArgs) Handles btnToday.Click 101 Today() 102 End Sub 103End Class 104
回答1件
あなたの回答
tips
プレビュー