antdui-demo/Views/CalendarDemo.cs
2024-09-06 16:54:03 +08:00

48 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AntdUI;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace AntdUIDemo.Views
{
public partial class CalendarDemo : UserControl
{
private AntdUI.Window window;
public CalendarDemo(AntdUI.Window _window)
{
window = _window;
InitializeComponent();
InitData();
BindEventHandler();
}
private void BindEventHandler()
{
calendar.DateChanged += Calendar_DateChanged;
}
private void Calendar_DateChanged(object sender, DateTimeEventArgs e)
{
AntdUI.Message.info(window, e.Value.ToString("yyyy-MM-dd"), autoClose: 1);
}
private void InitData()
{
calendar.BadgeAction = dates =>
{
// dates 参数为 DateTime[] 数组长度固定为2返回UI上显示的开始日期与结束日期
// DateTime start_date = dates[0], end_date = dates[1];
var now = dates[1];
return new List<DateBadge> {
new DateBadge(now.ToString("yyyy-MM-dd"),0),
new DateBadge(now.AddDays(-20).ToString("yyyy-MM-dd"),5),
new DateBadge(now.AddDays(-2).ToString("yyyy-MM-dd"),99),
new DateBadge(now.AddDays(-6).ToString("yyyy-MM-dd"),998,Color.FromArgb(112, 237, 58)),
};
};
calendar.LoadBadge();
}
}
}