非常简单的几十行代码就完成的事,如题选定的DataGridView 控件,创建一个属于自己的日历。
首先,从新建工程开始,看图片就明白,如下:新建工程
调整空白窗体大小
拖放控件
设置控件
修改控件属性
写代码
下面开始实现目标设计
第一步:考虑创建日历的列,可以参看别人日历的列是什么样的,于是用下面代码创建日历列,注:DataGridView控件名称命名为:事件日历
string[] 日历列 = new string[] { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
foreach (string 元素 in 日历列)
{
DataGridViewTextBoxColumn 列 = new DataGridViewTextBoxColumn();
列.HeaderText = 元素;
事件日历.Columns.Add(列);
}
以上是个人喜欢的创建代码写法,当然也可以每列写代码创建,我也不会说什么的,只能说句随缘了。运行上面代码可以看到创建的列了。
第二步:日历该显示多少行?依然可以参看可以看到的日历,包括VS自带日历控件都可以。下面创建6行空行
事件日历.Rows.Add(6);
那么,现在代码应该如下:
string[] 日历列 = new string[] { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
foreach (string 元素 in 日历列)
{
DataGridViewTextBoxColumn 列 = new DataGridViewTextBoxColumn();
列.HeaderText = 元素;
事件日历.Columns.Add(列);
}
事件日历.Rows.Add(6);
运行上面代码可以看到创建的列和6行空行了,这样一个日历的壳就编写好了。
第三步:试着给创建好的单元格赋值
int 计数 = 0;
for (int 行 = 0; 行 < 事件日历.RowCount; 行++)
{
for (int 列 = 0; 列 < 事件日历.ColumnCount; 列++)
{
计数++;
if (计数 > 31) break;
事件日历.Rows[行].Cells[列].Value = 计数.ToString("00");
}
}
那么,现在代码应该如下:
string[] 日历列 = new string[] { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
foreach (string 元素 in 日历列)
{
DataGridViewTextBoxColumn 列 = new DataGridViewTextBoxColumn();
列.HeaderText = 元素;
事件日历.Columns.Add(列);
}
事件日历.Rows.Add(6);
int 计数 = 0;
for (int 行 = 0; 行 < 事件日历.RowCount; 行++)
{
for (int 列 = 0; 列 < 事件日历.ColumnCount; 列++)
{
计数++;
if (计数 > 31) break;
事件日历.Rows[行].Cells[列].Value = 计数.ToString("00");
}
}
运行上面代码,可以看到类似如下图
从上图看,现在可以创建正确的日历了,只要把本月1日是星期几对应填到单元格就行了,还有本月有多少天加以控制,那么,这个日历就算编写完成了。
第四步:完成日历编写关键,获得2个数据,获得数据的写法很多,这里不啰嗦,用我自己的写法,其他的随缘随喜了,下面代码完成
int 星期值 = Convert.ToInt16(DateTime.Parse(DateTime.Now.ToString("yyyy年MM月01日")).DayOfWeek);
int 月天数 = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
修改上面代码,那么,现在代码应该如下:
string[] 日历列 = new string[] { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
foreach (string 元素 in 日历列)
{
DataGridViewTextBoxColumn 列 = new DataGridViewTextBoxColumn();
列.HeaderText = 元素;
事件日历.Columns.Add(列);
}
事件日历.Rows.Add(6);
int 计数 = 0;
int 星期值 = Convert.ToInt16(DateTime.Parse(DateTime.Now.ToString("yyyy年MM月01日")).DayOfWeek);
int 月天数 = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
for (int 行 = 0; 行 < 事件日历.RowCount; 行++)
{
if (行 > 0) 星期值 = 0;
for (int 列 = 星期值; 列 < 事件日历.ColumnCount; 列++)
{
计数++;
if (计数 > 月天数) break;
事件日历.Rows[行].Cells[列].Value = 计数.ToString("00");
}
}
运行如上代码,可以看到类似下图效果(截图电脑本地日期:2013年4月20日)
当然,以上代码看到的和上图有点不一样,呵呵,这张图片是实现上月下月日期全部填满的,下面会说到,到现在为止,整个日历就编写完成。
第五步:测试正确?试着更改电脑时间为3月1日和5月1日分别运行看,可以看到类似如下图片
我调试是正确的,你?你自己清楚,哈哈。。。。。。
第六步:完善1,填充下月日期到满后面所有单元格,修改一句代码就可以,如下
if (计数 > 月天数) 计数 = 1;
那么,现在代码应该如下:
string[] 日历列 = new string[] { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
foreach (string 元素 in 日历列)
{
DataGridViewTextBoxColumn 列 = new DataGridViewTextBoxColumn();
列.HeaderText = 元素;
事件日历.Columns.Add(列);
}
事件日历.Rows.Add(6);
int 计数 = 0;
int 星期值 = Convert.ToInt16(DateTime.Parse(DateTime.Now.ToString("yyyy年MM月01日")).DayOfWeek);
int 月天数 = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
for (int 行 = 0; 行 < 事件日历.RowCount; 行++)
{
if (行 > 0) 星期值 = 0;
for (int 列 = 星期值; 列 < 事件日历.ColumnCount; 列++)
{
计数++;
if (计数 > 月天数) 计数 = 1;
事件日历.Rows[行].Cells[列].Value = 计数.ToString("00");
}
}
很简单吧。现在就剩下填充上月日期,完善2,获得上月天数填充就可以了,有人可能觉得这步不容易,不要想多了,也很简单,把上面列循环语句拿来修改就可以正确填充单元格数据,实现代码如下
int 上月天数 = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month - 1);
for (int 列 = 事件日历.ColumnCount - 1; 列 >= 0; 列--)
{
if (事件日历.Rows[0].Cells[列].Value == null)
{
事件日历.Rows[0].Cells[列].Value = 上月天数.ToString("00");
上月天数--;
}
}
当然写法不止这一种,我只发布我的写法,其他随缘随喜了。
那么,现在代码应该如下:
string[] 日历列 = new string[] { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
foreach (string 元素 in 日历列)
{
DataGridViewTextBoxColumn 列 = new DataGridViewTextBoxColumn();
列.HeaderText = 元素;
事件日历.Columns.Add(列);
}
事件日历.Rows.Add(6);
int 计数 = 0;
int 星期值 = Convert.ToInt16(DateTime.Parse(DateTime.Now.ToString("yyyy年MM月01日")).DayOfWeek);
int 月天数 = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
for (int 行 = 0; 行 < 事件日历.RowCount; 行++)
{
if (行 > 0) 星期值 = 0;
for (int 列 = 星期值; 列 < 事件日历.ColumnCount; 列++)
{
计数++;
if (计数 > 月天数) 计数 = 1;
事件日历.Rows[行].Cells[列].Value = 计数.ToString("00");
}
}
int 上月天数 = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month - 1);
for (int 列 = 事件日历.ColumnCount - 1; 列 >= 0; 列--)
{
if (事件日历.Rows[0].Cells[列].Value == null)
{
事件日历.Rows[0].Cells[列].Value = 上月天数.ToString("00");
上月天数--;
}
}
第七步,设置单元格焦点为当日所在,美化控件颜色和控件一些属性设置,则整个日历设计就完美结束了,哈哈。。。。。。好吧,单元格焦点实现代码
事件日历.CurrentCell = 事件日历.Rows[行].Cells[列];
把这句加入后,现在代码应该如下:
string[] 日历列 = new string[] { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
foreach (string 元素 in 日历列)
{
DataGridViewTextBoxColumn 列 = new DataGridViewTextBoxColumn();
列.HeaderText = 元素;
事件日历.Columns.Add(列);
}
事件日历.Rows.Add(6);
int 计数 = 0;
int 星期值 = Convert.ToInt16(DateTime.Parse(DateTime.Now.ToString("yyyy年MM月01日")).DayOfWeek);
int 月天数 = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
for (int 行 = 0; 行 < 事件日历.RowCount; 行++)
{
if (行 > 0) 星期值 = 0;
for (int 列 = 星期值; 列 < 事件日历.ColumnCount; 列++)
{
计数++;
if (计数 > 月天数) 计数 = 1;
事件日历.Rows[行].Cells[列].Value = 计数.ToString("00");
if(计数 == DateTime.Now.Day) 事件日历.CurrentCell = 事件日历.Rows[行].Cells[列];
}
}
int 上月天数 = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month - 1);
for (int 列 = 事件日历.ColumnCount - 1; 列 >= 0; 列--)
{
if (事件日历.Rows[0].Cells[列].Value == null)
{
事件日历.Rows[0].Cells[列].Value = 上月天数.ToString("00");
上月天数--;
}
}
这篇文章到此收工啰,其他的。。。。。。
那天随便写写,后来又做了测试,今天随便看了下,觉得还是写一下较好,代码如下:
int 上月天数 = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month - 1);
星期值 = Convert.ToInt16(DateTime.Parse(DateTime.Now.ToString("yyyy年MM月01日")).DayOfWeek);
for (int 列 = 星期值 - 1; 列 >= 0; 列--)
{
事件日历.Rows[0].Cells[列].Value = 上月天数.ToString("00");
上月天数--;
}
微软提供计算农历函数:using System.Globalization;
internal enum 天干 { 南無阿弥陀佛, 甲, 乙, 丙, 丁, 戊, 己, 庚, 辛, 壬, 癸 }
internal enum 地支 { 南無释迦牟尼佛, 子, 丑, 寅, 卯, 辰, 巳, 午, 未, 申, 酉, 戌, 亥 }
internal enum 生肖 { 南無阿弥陀佛, 鼠, 牛, 虎, 兔, 龙, 蛇, 马, 羊, 猴, 鸡, 狗, 猪 }
internal enum 中月 { 南無阿弥陀佛, 正, 二, 三, 四, 五, 六, 七, 八, 九, 十, 冬, 腊 }
internal enum 中数 { 〇, 一, 二, 三, 四, 五, 六, 七, 八, 九 }
ChineseLunisolarCalendar 微软农历 = new ChineseLunisolarCalendar();
int 甲子60数 = 微软农历.GetSexagenaryYear(DateTime.Now);
string 年干支 = ((天干)(微软农历.GetCelestialStem(甲子60数))).ToString()
+ ((地支)(微软农历.GetTerrestrialBranch(甲子60数))).ToString()
+ "〖" + ((生肖)(微软农历.GetTerrestrialBranch(甲子60数))).ToString() + "〗";
string 中文年 = "";
foreach (char 元素 in 微软农历.GetYear(DateTime.Now).ToString())
{ 中文年 += ((中数)(int.Parse(元素.ToString()))).ToString(); } 中文年 += "年";
string 中农历月 = "";
if (微软农历.IsLeapYear(微软农历.GetYear(DateTime.Now)))
if (微软农历.GetMonth(DateTime.Now) >= 微软农历.GetLeapMonth(微软农历.GetYear(DateTime.Now)))
中农历月 = (微软农历.GetMonth(DateTime.Now) == 微软农历.GetLeapMonth(微软农历.GetYear(DateTime.Now))) ?
"闰" + ((中月)微软农历.GetLeapMonth(微软农历.GetYear(DateTime.Now)) - 1).ToString() :
((中月)微软农历.GetMonth(DateTime.Now) - 1).ToString() + "月";
else
中农历月 = ((中月)微软农历.GetMonth(new DateTime(2013, 5, 17))).ToString() + "月";
int 农历日 = 微软农历.GetDayOfMonth(new DateTime(2013, 5, 17));
string 中农历日 = "";
if (农历日 == 10) 中农历日 = "初十";
else if (农历日 == 20) 中农历日 = "二十";
else if (农历日 == 30) 中农历日 = "三十";
else if (农历日 < 10) 中农历日 = "初" + ((中数)(农历日)).ToString();
else if (农历日 > 10 && 农历日 < 20) 中农历日 = "十" + ((中数)(农历日) - 10).ToString();
else if (农历日 > 20 && 农历日 < 30) 中农历日 = "廿" + ((中数)(农历日) - 20).ToString();
int 农历月的天数 = 微软农历.GetDaysInMonth(微软农历.GetYear(DateTime.Now), 微软农历.GetMonth(DateTime.Now));
string 农历月干支 = "", 农历日干支 = "";
月日干支(out 农历月干支, out 农历日干支, DateTime.Now);
internal enum 星座 { 白羊座, 金牛座, 双子座, 巨蟹座, 狮子座, 处女座, 天秤座, 天蝎座, 射手座, 摩羯座, 水瓶座, 双鱼座 }
private void 星座计算(out string 星座名, DateTime 阳历日期)
{
星座名 = "";
int 合成值 = 阳历日期.Month * 100 + 阳历日期.Day;
if (合成值 >= 101 && 合成值 <= 119) 星座名 = ((星座)9).ToString();
if (合成值 >= 120 && 合成值 <= 218) 星座名 = ((星座)10).ToString();
if (合成值 >= 219 && 合成值 <= 320) 星座名 = ((星座)11).ToString();
if (合成值 >= 321 && 合成值 <= 419) 星座名 = ((星座)0).ToString();
if (合成值 >= 420 && 合成值 <= 520) 星座名 = ((星座)1).ToString();
if (合成值 >= 521 && 合成值 <= 620) 星座名 = ((星座)2).ToString();
if (合成值 >= 621 && 合成值 <= 722) 星座名 = ((星座)3).ToString();
if (合成值 >= 723 && 合成值 <= 822) 星座名 = ((星座)4).ToString();
if (合成值 >= 823 && 合成值 <= 922) 星座名 = ((星座)5).ToString();
if (合成值 >= 923 && 合成值 <= 1022) 星座名 = ((星座)6).ToString();
if (合成值 >= 1023 && 合成值 <= 1121) 星座名 = ((星座)7).ToString();
if (合成值 >= 1122 && 合成值 <= 1221) 星座名 = ((星座)8).ToString();
if (合成值 >= 1222) 星座名 = ((星座)9).ToString();
}
private void 月日干支(out string 农历月干支, out string 农历日干支, DateTime 阳历日期)
{/*<a target=_blank href="http://baike.baidu.com/link?url=CJmK0t4Nnwe41e2mgIwlGfdrRCEq1mijDKuGEDSSGOP8v9YiYrjfQ_Dfd75KNWEc" target="_blank">由甲子日开始,按顺序先后排列,六十日刚好是一个干支的周期。农历日干支采用定位比较算法
正月是由寅开始,每个月的地支固定不变,然后依次与天干组合;
由第一年的正月丙寅月、二月是丁卯月、三月是戊辰。从甲子月到癸亥月,共六十甲子,刚好五年。</a>*/
农历月干支 = ""; 农历日干支 = ""; 农历时干支 = "";
ChineseLunisolarCalendar 微软农历 = new ChineseLunisolarCalendar();
int 月基数 = 微软农历.GetCelestialStem(微软农历.GetSexagenaryYear(阳历日期));
if (月基数 > 5) 月基数 -= 5;/*阳阴归类*/
int 农历月 = 微软农历.GetMonth(阳历日期), 农历年 = 微软农历.GetYear(阳历日期), 润月 = 微软农历.GetLeapMonth(农历年);
农历月 = (微软农历.IsLeapYear(农历年) && 农历月 >= 润月) ? ((农历月 == 润月) ? 润月 - 1 : 农历月 - 1) : 农历月;
int 干偏移 = (((月基数 * 2 + 1) % 10) + (农历月 - 1)); if (干偏移 > 10) 干偏移 -= 10;
int 支偏移 = 农历月 + 2; if (支偏移 > 12) 支偏移 -= 12;
农历月干支 = ((天干)干偏移).ToString() + ((地支)支偏移).ToString() + "月";
int 间隔天数 = (阳历日期.Date - new DateTime(2001, 1, 1)).Days % 60;
Func<List<int>, List<int>> 推算 = delegate(List<int> 数)
{
List<int> 干支值 = new List<int>();
干偏移 = 间隔天数 % 10 + 数[0]; if (干偏移 > 10) 干偏移 -= 10;
支偏移 = 间隔天数 % 12 + 数[1]; if (支偏移 > 12) 支偏移 -= 12;
干支值.Add(干偏移); 干支值.Add(支偏移);
return 干支值;
};
List<int> 日干支值 = 间隔天数 >= 0 ? 推算(new List<int> { 1, 1 }) : 推算(new List<int> { 11, 13 });
农历日干支 = ((天干)日干支值[0]).ToString() + ((地支)日干支值[1]).ToString() + "日";
int 小时数 = 阳历日期.Hour;
if (日干支值[0] > 5) 日干支值[0] -= 5;/*阳阴归类*/
日干支值[0] *= 2; 日干支值[0] -= 1;/*归阳*/
int 时辰支 = 小时数 % 2 == 0 ? 小时数 / 2 + 1 : 小时数 / 2 + 2; if (时辰支 > 12) 时辰支 -= 12;
int 时辰干 = 日干支值[0] + 时辰支 - 1; if (时辰干 > 10) 时辰干 -= 10;
农历时干支 = ((天干)时辰干).ToString() + ((地支)时辰支).ToString() + "时";
}
/*新增时干支推算2013-6-4*/依据 点击打开链接
发现网络上下载的万年历月和日干支错了,唯佛教日历没错?!因此,不再使用错的万年历核对,这种阳历推算都回错的万年历作者不负责任啊.
空闲时间弄阴历好长时间,这是完成作品展示.阴历转阳历通过找阴历确定阳历。
这里转载一段算法,同时随喜和感谢原作者.
private class 太阳节气
{
private DateTime 节气值;
private string 名称;
public DateTime 节气时间
{
get
{ return 节气值; }
set
{ 节气值 = value; }
}
public string 节气名
{
get
{ return 名称; }
set
{ 名称 = value; }
}
}
internal enum 节气 { 小寒, 大寒, 立春, 雨水, 惊蛰, 春分, 清明, 谷雨, 立夏, 小满, 芒种, 夏至, 小暑, 大暑, 立秋, 处暑, 白露, 秋分, 寒露, 霜降, 立冬, 小雪, 大雪, 冬至 }
private 太阳节气[] 节气24计(DateTime 阳历日期)
{ return 节气24算(阳历日期.Year, 阳历日期.Month); }
private 太阳节气[] 节气24算(int 年, int 月)
{
太阳节气[] 太阳综合信息 = new 太阳节气[2];
for (int 数 = 月 * 2 - 1; 数 <= 月 * 2; 数++)
{
太阳节气 太阳信息 = new 太阳节气();
double 日差值 = 差天数值(年, 数, true);
double 阳历年日差 = 阳历年日差天数(2005, Math.Floor(日差值));
double sm1 = Math.Floor(阳历年日差 / 100);
int 天中时 = (int)Math.Floor((double)小数尾数(日差值) * 24);
int 天中分钟 = (int)Math.Floor((double)(小数尾数(日差值) * 24 - 天中时) * 60);
int 节气月 = (int)Math.Ceiling((double)数 / 2);
int 月中天 = (int)阳历年日差 % 100;
太阳信息.节气时间 = new DateTime(年, 节气月, 月中天, 天中时, 天中分钟, 0);
太阳信息.节气名 = ((节气)(数 - 1)).ToString();
太阳综合信息[数 - 月 * 2 + 1] = 太阳信息;
}
return 太阳综合信息;
}
private double 小数尾数(double 原小数)
{ return 原小数 - Math.Floor(原小数); }
private double 差天数值(int 年, int 数, bool 控制)
{
double 儒略日 = 年 * (365.2423112 - 6.4e-14 * (年 - 100) * (年 - 100) - 3.047e-8 * (年 - 100)) + 15.218427 * 数 + 1721050.71301;
double 角度 = 3e-4 * 年 - 0.372781384 - 0.2617913325 * 数;
double 年差实均数 = (1.945 * Math.Sin(角度) - 0.01206 * Math.Sin(2 * 角度)) * (1.048994 - 2.583e-5 * 年);
double 朔差实均数 = -18e-4 * Math.Sin(2.313908653 * 年 - 0.439822951 - 3.0443 * 数);
double vs = (控制) ? (儒略日 + 年差实均数 + 朔差实均数 - 等效标准天数(年, 1, 0) - 1721425) : (儒略日 - 等效标准天数(年, 1, 0) - 1721425);
return vs;
}
private double 阳历年日差天数(int 年, double 值)
{
int 取值 = 1;
for (int 数 = 1; 数 <= 12; 数++)
{
int 差 = 日差天数(年, 数 + 1, 1) - 日差天数(年, 数, 1);
if (值 <= 差 || 数 == 12) { 取值 = 数; break; }
else 值 -= 差;
}
return 100 * 取值 + 值;
}
private double 等效标准天数(int 年, int 月, int 日)
{
double 等天数 = (年 - 1) * 365 + Math.Floor((double)((年 - 1) / 4)) + 日差天数(年, 月, 日) - 2;//朱利安的等效标准天数
if (年 > 1582) 等天数 += -Math.Floor((double)((年 - 1) / 100)) + Math.Floor((double)((年 - 1) / 400)) + 2;//格利高里的等效标准天数
return 等天数;
}
private int 日差天数(int 年, int 月, int 日)
{
int 判断值 = 判断何历(年, 月, 日, 1), 差天数 = 0;
int[] 月天数 = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (判断值 == 1)
if ((年 % 100 != 0 && 年 % 4 == 0) || (年 % 400 == 0)) 月天数[2] += 1;
else
if (年 % 4 == 0) 月天数[2] += 1;
for (int i = 0; i <= 月 - 1; i++) 差天数 += 月天数[i];
差天数 += 日;
if (年 == 1582)
{
if (判断值 == 1) 差天数 -= 10;
if (判断值 == -1) 差天数 = 0;//无穷
}
return 差天数;
}
private int 判断何历(int 年, int 月, int 日, int 选择)
{
if (选择 == 1)
return (年 > 1582 || (年 == 1582 && 月 > 10) || (年 == 1582 && 月 == 10 && 日 > 14)) ? 1 :
(年 == 1582 && 月 == 10 && 日 >= 5 && 日 <= 14) ? -1 : 0;
if (选择 == 2) return 1;//格利高里
if (选择 == 3) return 0;//朱利安
return -1;//空
}
好了,这个日历到此结束,24节气网络上搜索有现成的类文件提供下载而且不是使用编辑的数据数组,是公式演算太阳在黄经角度的,与其采用数组存什么阴历资料节气资料等资料,我更相信用公式演算的方式.有点遗憾微软这个函数居然没找到计算节气的,节气属于阳历演算范畴,希望以后微软会更新出计算节气的。
最后,看看用微软和自己写的完成作品图。支持范围:它应介于 02/19/1901 00:00:00(公历日期)和 01/28/2101 23:59:59(公历日期)之间(包括这两个日期)。
自己摸索修正一些错误,几经调试核对,已定型了,上面代码也几经更新过了:更新对闰月计算,处理了传参数时不带时间避免带时间计算误差,优化和修正一些代码写法和参数错误。
轮换图片的升起提示框:
private void 升起提示窗体(string 内容)
{
List<Bitmap> 图片集 = new List<Bitmap>();
图片集.Add(资源文件.观世音菩萨); 图片集.Add(资源文件.皮惹草);
图片集.Add(资源文件.白雪公主); 图片集.Add(资源文件.灰姑娘);
图片集.Add(资源文件.米老鼠); 图片集.Add(资源文件.米老鼠伴);
图片集.Add(资源文件.唐老鸭); 图片集.Add(资源文件.小狗);
图片集.Add(资源文件.小鹿);
Form 升起提示框 = new Form();
int 序 = DateTime.Now.Minute % 图片集.Count, 字符串长度 = 内容.Length * 13;
升起提示框.Width = 图片集[序].Width + 19;
升起提示框.Height = 图片集[序].Height + 38;
升起提示框.BackgroundImage = 图片集[序];
升起提示框.Icon = 资源文件.闹钟;
升起提示框.MaximizeBox = false;
升起提示框.TopMost = true;
升起提示框.Text = 内容;
if (升起提示框.Width < 128 + 字符串长度) 升起提示框.Width = 128 + 字符串长度;
Point 坐标 = new Point(Screen.PrimaryScreen.WorkingArea.Width - 升起提示框.Width, Screen.PrimaryScreen.WorkingArea.Height);// - 升起提示框.Height
升起提示框.PointToScreen(坐标);
升起提示框.Location = 坐标;
升起提示框.Show();
for (int 升 = 0; 升 <= 升起提示框.Height; 升 += 2) 升起提示框.Location = new Point(坐标.X, 坐标.Y - 升);
}
纳音五行
金{1 2 9 10 17 18 31 32 39 40 47 48 }{海中金 剑锋金 白腊金 沙中金 金箔金 钗钏金}
火{3 4 11 12 25 26 33 34 41 42 55 56}{炉中火 山头火 霹雷火 山下火 佛光火 天上火}
木{5 6 19 20 27 28 35 36 49 50 57 58}{大林木 杨柳木 松柏木 平地木 桑松木 石榴木}
土{7 8 15 16 23 24 37 38 45 46 53 54}{路旁土 城墙土 屋上土 壁上土 大驿土 沙中土}
水{13 14 21 22 29 30 43 44 51 52 59 60}{涧下水 泉中水 常流水 天河水 大溪水 大海水}
甲子乙丑海中金,丙寅丁卯炉中火,戊辰己巳大林木,
庚午辛未路旁土,壬申癸酉剑锋金,甲戌乙亥山头火,
丙子丁丑涧下水,戊寅己卯城头土,庚辰辛巳白蜡金,
壬午癸未杨柳木,甲申乙酉泉中水,丙戌丁亥屋上土,
戊子己丑霹雳火,庚寅辛卯松柏木,壬辰癸巳长流水,
甲午乙未沙中金,丙申丁酉山下火,戊戌己亥平地木,
庚子辛丑壁上土,壬寅癸卯金箔金,甲辰乙巳佛灯火,
丙午丁未天河水,戊申己酉大驿土,庚戌辛亥钗钏金,
壬子癸丑桑柘木,甲寅乙卯大溪水,丙辰丁巳沙中土,
戊午己未天上火,庚申辛酉石榴木,壬戌癸亥大海水。
private enum 五行 { 南無观世音菩萨, 木, 火, 土, 金, 水 }
天干地支阳阴五行对照表
甲 乙 丙 丁 戊 己 庚 辛 壬 癸
阳 阴 阳 阴 阳 阴 阳 阴 阳 阴
木 木 火 火 土 土 金 金 水 水
23-01 子01-03 丑03-05 寅05-07 卯07-09 辰09-11 巳
11-13 午13-15 未15-17 申17-19 酉19-21 戊21-23 亥
子 丑 寅 卯 辰 巳 午 未 申 酉 戌 亥
鼠 牛 虎 兔 龙 蛇 马 羊 猴 鸡 狗 猪
阳 阴 阳 阴 阳 阴 阳 阴 阳 阴 阳 阴
水 土 木 木 土 火 火 土 金 金 土 水
-------------------------------------------------------
拿来演练算法很有意思的,如上面新增的时干支算法,经过推导最后写出的算法却很简单几句就完成,不像所说的周折。
Func<int, int> 天干阳阴五行推算 = delegate(int 数)
{ return 数 % 2 == 0 ? 数 / 2 : 数 / 2 + 1; };
Func<int, int> 地支阳阴五行推算 = delegate(int 数)
{
if (数 == 3 || 数 == 4) return 1;
else if (数 == 6 || 数 == 7) return 2;
else if (数 == 9 || 数 == 10) return 4;
else if (数 == 1 || 数 == 12) return 5;
else return 3;
};
看这个觉得站主很专的:http://www.bdlrl.com/_private/15nlcxb/06rgz.html
2015年03月02日→星座:双鱼座
二〇一五年正月十二
乙未〖羊〗戊寅月丁丑日己酉时
今属:火;五行:木土火金;缺:水。
纳音五行:沙中金。
净宗七祖省常法师圆寂日
首先感谢访问,来者都是缘份。今天有人私信问:qq_25559193: 为什么你不吧DATAGRIDVIEW控件,带有法定节假日的程序写出来呀! 表示后面的看不懂了
来看了看,最后觉得补充还是可以的,其实,会填充单元格数字就会填充其他文字,只不过是加了些判断去填充单元格内容而已,以前本不想发布出来,既然有人提了,就顺便举个简单的例子,不多作解释.
DateTime 上月 = new DateTime(阳历日期.Year, 阳历日期.Month, 1).AddDays(-1);
int 上月天数 = DateTime.DaysInMonth(上月.Year, 上月.Month);
string 节气信息="";
阳历转阴历 阳历转阴历数据 = new 阳历转阴历();/*调用之上已发布的代码写的一个类文件*/
for (int 列 = 星期值 - 1; 列 >= 0; 列--)
{
DateTime 合成日期 = new DateTime(上月.Year, 上月.Month, 上月天数, 阳历日期.Hour, 阳历日期.Minute, 阳历日期.Second);
阳历转阴历.太阳节气[] 节气 = 阳历转阴历数据.节气24计(合成日期);
if (节气[0].节气时间.Date == 合成日期.Date) 节气信息 = 节气[0].节气名;
if (节气[1].节气时间.Date == 合成日期.Date) 节气信息 = 节气[1].节气名;
自定日历.Rows[0].Cells[列].Value = 上月天数.ToString("00\n") + 节气信息 + "\n";
上月天数--;
}