public void Combobox_loaded(DateTime currentTime) { comboBoxYears.ItemsSource = datas100Years; int year = currentTime.Year; comboBoxYears.SelectedItem = $"{year}年"; comboBoxMonths.SelectedItem = $"{currentTime.Month}月"; int daysOfSolarMonth = DaysOfSolarMonth(currentTime.Year, currentTime.Month); switch (daysOfSolarMonth) { case 28: comboBoxDays.ItemsSource = datas28Days; break; case 29: comboBoxDays.ItemsSource = datas29Days; break; case 30: comboBoxDays.ItemsSource = datas30Days; break; case 31: comboBoxDays.ItemsSource = datas31Days; break; default: break; } comboBoxDays.SelectedIndex = currentTime.Day - 1; comboBoxLunarYears.ItemsSource = datas100Years; comboBoxLunarYears.SelectedItem = LunarCalendar.GetLunarYear(currentTime.Year, currentTime.Month, currentTime.Day) + "年"; string LunarDay = LunarCalendar.GetLunarDay(currentTime.Year, currentTime.Month, currentTime.Day, false); comboBoxLunarMonths.SelectedItem = LunarCalendar.GetStringLunarMonth(currentTime.Year, currentTime.Month, currentTime.Day); int lunarMonthDays = LunarCalendar.GetIntLunarMonth(currentTime.Year, currentTime.Month, currentTime.Day)[1]; if (lunarMonthDays == 29) { comboBoxLunarDays.ItemsSource = datas29LunarDays; } else { comboBoxLunarDays.ItemsSource = datas30LunarDays; } comboBoxLunarDays.SelectedItem = LunarCalendar.GetLunarDay(currentTime.Year, currentTime.Month, currentTime.Day, true); }
//刷新页面函数 public void Refresh(DateTime dateTime) { foreach (Button button in list) { button.IsEnabled = true; //使按钮能点击 } list.Clear(); //清空链表 for (int i = 0; i < 7; i++) { buttonArray[0, i].Content = ""; buttonArray[4, i].Content = ""; buttonArray[5, i].Content = ""; } ButtonTodayTemp.Background = brushWheat; ButtonTodayTemp.Foreground = brushBlack; if (priClickButton != null) { priClickButton.BorderBrush = brushTransparent; } //星期六、日的字体颜色为brown for (int i = 0; i < 6; i++) { buttonArray[i, 6].Foreground = brushBrown; //星期六 buttonArray[i, 0].Foreground = brushBrown; //星期日 } DateTime date = new DateTime(dateTime.Year, dateTime.Month, 1); int weekday = (int)date.DayOfWeek; int number = 0; int maxDay = DateTime.DaysInMonth(dateTime.Year, dateTime.Month); for (int i = 0; i < 6; i++) { for (int j = 0; j < 7; j++) { number = i * 7 + j + 1 - weekday; if (number > 0 && number <= maxDay) { if (number == dateTime.Day) { priClickButton = buttonArray[i, j]; } string lunarDate = LunarCalendar.GetLunarDay(dateTime.Year, dateTime.Month, number, false); string Blank2 = GetBlank(lunarDate.Length); if (number < 10) { buttonArray[i, j].Content = Blank2 + $" {number}\n" + lunarDate; } else { buttonArray[i, j].Content = Blank2 + $"{number}\n" + lunarDate; } dayInButton[i, j] = number; number++; } else { buttonArray[i, j].IsEnabled = false;//使按钮失效 list.Add(buttonArray[i, j]); dayInButton[i, j] = 0; } } } priClickButton.BorderBrush = brushBrown; DateTime Today = DateTime.Now; if (dateTime.Year == Today.Year && dateTime.Month == Today.Month) { ButtonTodayTemp.Background = brushBrown; ButtonTodayTemp.Foreground = brushWheat; } }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { DateTime currentTime = DateTime.Now; Combobox_loaded(currentTime); TextBlock_loaded(); //星期六、日的字体颜色为brown for (int i = 0; i < 6; i++) { buttonArray[i, 6].Foreground = brushBrown; //星期六 buttonArray[i, 0].Foreground = brushBrown; //星期日 } DateTime dateTime = new DateTime(currentTime.Year, currentTime.Month, 1); int weekday = (int)dateTime.DayOfWeek; int number = 0; dayInButton = new int[6, 7]; /* * while (weekday < 7) * { * if (number == currentTime.Day) * ButtonTodayTemp = buttonArray[0, weekday]; * string lunarDate = LunarCalendar.GetLunarDay(currentTime.Year, currentTime.Month, number, false); * string Blank1 = GetBlank(lunarDate.Length); * buttonArray[0, weekday].Content = Blank1 + $" {number}\n" + lunarDate; * dayInButton[0, weekday] = number; * weekday++; * number++; * } */ int maxDay = DateTime.DaysInMonth(currentTime.Year, currentTime.Month); list = new List <Button>(); for (int i = 0; i < 6; i++) { for (int j = 0; j < 7; j++) { number = i * 7 + j + 1 - weekday; if (number > 0 && number <= maxDay) { if (number == currentTime.Day) { ButtonTodayTemp = buttonArray[i, j]; } string lunarDate = LunarCalendar.GetLunarDay(currentTime.Year, currentTime.Month, number, false); string Blank2 = GetBlank(lunarDate.Length); if (number < 10) { buttonArray[i, j].Content = Blank2 + $" {number}\n" + lunarDate; } else { buttonArray[i, j].Content = Blank2 + $"{number}\n" + lunarDate; } dayInButton[i, j] = number; } else { buttonArray[i, j].IsEnabled = false;//使按钮失效 list.Add(buttonArray[i, j]); dayInButton[i, j] = 0; } } } if (ButtonTodayTemp != null) { ButtonTodayTemp.Background = brushBrown; ButtonTodayTemp.Foreground = brushWheat; } }