FormCalendar.cs

using System;
using System.Drawing;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace LunisolarCalendar
{
    public partial class FormCalendar : Form
    {
        #region AnimateWindow
        [DllImport("user32.dll", EntryPoint = "AnimateWindow")]
        private static extern bool AnimateWindow(IntPtr handle, int ms, int flags);
        #endregion
        #region
        private EastAsianLunisolarCalendar lunarCalendar;
        private readonly string animals, gan, zhi;
        #endregion

        public FormCalendar()
        {
            #region
            InitializeComponent();
            this.StartPosition = FormStartPosition.Manual; // 窗体的位置由 Location 属性确定。
            this.DesktopLocation = new Point(Screen.GetWorkingArea(this).Size - this.Size);
            this.AutoSizeMode = AutoSizeMode.GrowAndShrink; // 禁用手动调整大小。
            this.SizeGripStyle = SizeGripStyle.Hide;       // 隐藏调整大小手柄。
            statusStripInfo.SizingGrip = false;           // 隐藏状态栏大小调整手柄。
            toolComboBoxCulture.DropDownStyle = ComboBoxStyle.DropDownList;
            toolComboBoxCulture.ComboBox.DisplayMember = "DisplayName";
            toolComboBoxCulture.ComboBox.DataSource = new CultureInfo[] { CultureInfo.GetCultureInfo("zh-CN"), CultureInfo.GetCultureInfo("ko-KR") };
            monthCalendar.DataBindings.Add("SelectionEnd", datePicker, "Value");
            datePicker.CustomFormat = "yyyy-MM-dd";
            datePicker.Format = DateTimePickerFormat.Custom; // 自定义格式。
            datePicker.ShowUpDown = true;
            datePicker.MaxDate = lunarCalendar.MaxSupportedDateTime;
            datePicker.MinDate = lunarCalendar.MinSupportedDateTime;
            gan = "甲乙丙丁戊己庚辛壬癸";
            zhi = "子丑寅卯辰巳午未申酉戌亥";
            animals = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
            #endregion
        }

        #region FormLoad
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            AnimateWindow(this.Handle, 1000, 0x20010); // 居中逐渐显示。
        }
        #endregion

        #region FormClosing
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            AnimateWindow(this.Handle, 1000, 0x10010); // 居中逐渐隐藏。
        }
        #endregion

        #region LunisolarCalendar
        private void timerInfo_Tick(object sender, EventArgs e)
        {
            DateTime solar = monthCalendar.SelectionEnd;
            int year = lunarCalendar.GetYear(solar);
            int lm = lunarCalendar.GetMonth(solar);
            int day = lunarCalendar.GetDayOfMonth(solar);
            int leapMonth = lunarCalendar.GetLeapMonth(year);
            if (0 < leapMonth && leapMonth <= lm)
                --lm;
            int sm = solar.Month;
            leapMonth = lunarCalendar.GetLeapMonth(solar.Year);
            if (0 < leapMonth && leapMonth <= sm)
                ++sm;
            if (solar.Day <= lunarCalendar.GetDaysInMonth(solar.Year, sm))
                solar = lunarCalendar.ToDateTime(solar.Year, sm, solar.Day, 0, 0, 0, 0);
            this.Text = string.Format("农历 {0}{1}【{2}年】", gan[(year - 4) % 10], zhi[(year - 4) % 12], animals[(year - 4) % 12]);
            statusLabelTime.Text = string.Format("[{0:D}] [{1} {2:00}]", solar, DateTimeFormatInfo.CurrentInfo.MonthNames[lm - 1], day);
        }
        #endregion

        #region Application.CurrentCulture
        private void toolComboBoxCulture_SelectedIndexChanged(object sender, EventArgs e)
        {
            Application.CurrentCulture = toolComboBoxCulture.SelectedItem as CultureInfo;
            switch (Application.CurrentCulture.Name)
            {
                case "zh-CN":
                    lunarCalendar = new ChineseLunisolarCalendar();
                    break;
                case "ko-KR":
                    lunarCalendar = new KoreanLunisolarCalendar();
                    break;
            }
        }
        #endregion
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值