C# 阴历,阳历互转
来源:互联网 发布:网络教学和函授 编辑:程序博客网 时间:2024/04/30 11:13
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
namespace WinFormLunisolar
{
public partial class FormLunisolar : Form
{
#region
private readonly string animals;
private DateTimePicker lunarPicker, solarPicker;
private ChineseLunisolarCalendar lunarCalendar;
#endregion
public FormLunisolar()
{
#region
InitializeComponent();
animals = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
lunarCalendar = new ChineseLunisolarCalendar(); // 中国阴阳历。
lunarPicker = new DateTimePicker();
lunarPicker.Dock = DockStyle.Top;
lunarPicker.Format = DateTimePickerFormat.Custom; // 自定义格式。
lunarPicker.ShowUpDown = true; // 使用数值调节钮控件。
lunarPicker.ValueChanged += new EventHandler(lunarPicker_ValueChanged);
this.Controls.Add(lunarPicker);
solarPicker = new DateTimePicker();
solarPicker.Dock = DockStyle.Bottom;
solarPicker.Format = DateTimePickerFormat.Custom; // 自定义格式。
solarPicker.CustomFormat = "dddd yyyy'年'M'月'd'日'";
solarPicker.ShowUpDown = true; // 使用数值调节钮控件。
solarPicker.MaxDate = lunarCalendar.MaxSupportedDateTime;
solarPicker.ValueChanged += new EventHandler(solarPicker_ValueChanged);
solarPicker.Value = DateTime.Today;
this.Controls.Add(solarPicker);
this.TopMost = true; // 前端显示。
this.ShowInTaskbar = false; // 在 Windows 任务栏中隐藏窗体。
this.HelpButton = true; // 显示“帮助”按钮。
this.MaximizeBox = false; // 隐藏“最大化”按钮。
this.MinimizeBox = false; // 隐藏“最小化”按钮。
this.AutoScaleMode = AutoScaleMode.Font; // 根据字体的维度控制缩放。
this.Font = new Font(Font.Name, 12F);
this.ClientSize = new Size(192, 52);
this.AutoSizeMode = AutoSizeMode.GrowAndShrink; // 禁用手动调整大小。
this.SizeGripStyle = SizeGripStyle.Hide; // 隐藏调整大小手柄。
this.StartPosition = FormStartPosition.CenterScreen; // 在桌面居中显示。
#endregion
}
#region 计算阳历
private void lunarPicker_ValueChanged(object sender, EventArgs e)
{
DateTime solar = lunarPicker.Value;
int year = solar.Year;
int month = solar.Month;
int day = Math.Min(solar.Day, lunarCalendar.GetDaysInMonth(year, month));
int leapMonth = lunarCalendar.GetLeapMonth(year);
if (0 < leapMonth && leapMonth <= month)
++month;
solarPicker.Value = lunarCalendar.ToDateTime(year, month, day, 0, 0, 0, 0);
}
#endregion
#region 计算阴历
private void solarPicker_ValueChanged(object sender, EventArgs e)
{
DateTime solar = solarPicker.Value;
int year = lunarCalendar.GetYear(solar);
int month = lunarCalendar.GetMonth(solar);
int day = lunarCalendar.GetDayOfMonth(solar);
int leapMonth = lunarCalendar.GetLeapMonth(year);
if (0 < leapMonth && leapMonth <= month)
--month;
if (month == 2 && day > 28)
lunarPicker.CustomFormat = string.Format("{0}年 {1}年 {2}月{3}日", animals[(year - 4) % 12], year, month, day);
else
{
lunarPicker.CustomFormat = string.Format("{0}'年' yyyy'年'M'月'd'日'", animals[(year - 4) % 12]);
lunarPicker.Value = new DateTime(year, month, day);
}
}
#endregion
#region DesktopBounds
protected override void OnHelpButtonClicked(System.ComponentModel.CancelEventArgs e)
{
base.OnHelpButtonClicked(e);
e.Cancel = true;
using (FontDialog fontDialog = new FontDialog())
{
fontDialog.Font = this.Font;
fontDialog.ShowEffects = false;
if (fontDialog.ShowDialog(this) == DialogResult.OK)
{
this.Font = fontDialog.Font;
int sw = TextRenderer.MeasureText("星期日 0000年00月00日", this.Font).Width;
this.ClientSize = new Size(sw + 16, lunarPicker.Height + solarPicker.Height);
Size ws = Screen.GetWorkingArea(this).Size - this.Size;
this.DesktopLocation = new Point(ws.Width / 2, ws.Height / 2);
}
}
}
#endregion
}
}
- C# 阴历,阳历互转
- C# 中国阴历,阳历互转
- iOS阴历阳历互转
- 阴历阳历互转及节日程序
- 日期阴历转阳历
- 阴历转阳历java版
- 利用js显示阳历和阴历(转)
- 一个阴历阳历互相转化的类(c#源码)
- 一个阴历阳历互相转化的类(C#源码)
- 一个阴历阳历互相转化的类(c#源码)
- 一个阴历阳历互相转化的类(c#源码)
- 阴历阳历转换
- 阴历阳历转换
- 阴历阳历转换
- 阴历与阳历转换
- ASP阴历阳历转换
- 阴历阳历SQL转换
- 阴历+阳历时间
- 应用程序基础,andriod框架主题知识
- C# 调用画图工具打开图片
- andriod用户界面UI
- C# 检索IE缓存图片
- C#向前台页面中输出JS代码
- C# 阴历,阳历互转
- python 线程,GIL 和 ctypes
- PrintToExcel
- MyEclipse8.5插件安装 即性能优化 补充myeclipse6.5的
- Extension Method
- C# 获取文件信息并导出Excel,Xml报表
- POJ图论分类
- 生活大爆炸之何为光速
- 客户端访问webService简单应用