C#實(shí)現(xiàn)日歷效果
本文實(shí)例為大家分享了C#實(shí)現(xiàn)日歷效果的具體代碼,供大家參考,具體內(nèi)容如下
展示:
主要代碼:
public partial class calendar : Form ? ? { ? ? ? ? public calendar() ? ? ? ? { ? ? ? ? ? ? InitializeComponent(); ? ? ? ? } ? ? ? ? int year, month; ? ? ? ? private void textBoxMonth_TextChanged(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? if (textBoxMonth.Text == "") ? ? ? ? ? ? ? ? month = 0; ? ? ? ? ? ? month = Convert.ToInt32(textBoxMonth.Text); ? ? ? ? } ? ? ? ? private void buttonSearch_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? seach(); ? ? ? ? } ? ? ? ? private void textBoxYear_TextChanged(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? year = Convert.ToInt32(textBoxYear.Text); ? ? ? ? } ? ? ? ? private void buttonLastMonth_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? int year = Convert.ToInt32(textBoxYear.Text); ? ? ? ? ? ? int month=Convert.ToInt32(textBoxMonth.Text); ? ? ? ? ? ? if (year == 1 && month == 1) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? year = 1; ? ? ? ? ? ? ? ? month = 1; ? ? ? ? ? ? } ? ? ? ? ? ? else ? ? ? ? ? ? { ? ? ? ? ? ? ? ? if (month > 1) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? month--; ? ? ? ? ? ? ? ? ? ? textBoxMonth.Text = Convert.ToString(month); ? ? ? ? ? ? ? ? ? ? seach(); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? textBoxMonth.Text = Convert.ToString(12); ? ? ? ? ? ? ? ? ? ? year--; ? ? ? ? ? ? ? ? ? ? textBoxYear.Text = Convert.ToString(year); ? ? ? ? ? ? ? ? ? ? seach(); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? private void buttonNextMonth_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? int month = Convert.ToInt32(textBoxMonth.Text); ? ? ? ? ? ? if (month < 12) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? month++; ? ? ? ? ? ? ? ? textBoxMonth.Text = Convert.ToString(month); ? ? ? ? ? ? ? ? seach(); ? ? ? ? ? ? } ? ? ? ? ? ? else ? ? ? ? ? ? { ? ? ? ? ? ? ? ? textBoxMonth.Text = Convert.ToString(1); ? ? ? ? ? ? ? ? int year = Convert.ToInt32(textBoxYear.Text); ? ? ? ? ? ? ? ? year++; ? ? ? ? ? ? ? ? textBoxYear.Text = Convert.ToString(year); ? ? ? ? ? ? ? ? seach(); ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? private void buttonLastYear_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? int year = Convert.ToInt32(textBoxYear.Text); ? ? ? ? ? ? if(year>1) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? year--; ? ? ? ? ? ? ? ? textBoxYear.Text = Convert.ToString(year); ? ? ? ? ? ? ? ? textBoxMonth.Text = Convert.ToString(1); ? ? ? ? ? ? ? ? seach(); ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? private void buttonNextYear_Click(object sender, EventArgs e) ? ? ? ? { ? ? ? ? ? ? int year = Convert.ToInt32(textBoxYear.Text); ? ? ? ? ? ? year++; ? ? ? ? ? ? textBoxYear.Text = Convert.ToString(year); ? ? ? ? ? ? textBoxMonth.Text = Convert.ToString(1); ? ? ? ? ? ? seach(); ? ? ? ? } ? ? ? ? public void seach() ? ? ? ? { ? ? ? ? ? ? if (textBoxYear.Text == "" || textBoxMonth.Text == "") ? ? ? ? ? ? ? ? labelAlert.Text = "請(qǐng)輸入年份及月份"; ? ? ? ? ? ? else ? ? ? ? ? ? if (Convert.ToInt32(textBoxYear.Text) <= 0 || Convert.ToInt32(textBoxMonth.Text) <= 0 || Convert.ToInt32(textBoxMonth.Text) > 12) ? ? ? ? ? ? ? ? labelAlert.Text = "輸入的年份與月份不能小于0,月份不能大于12"; ? ? ? ? ? ? else ? ? ? ? ? ? { ? ? ? ? ? ? ? ? textBoxDemonstrate.Text = "周一 ? ?周二 ? ?周三 ? ?周四 ? ?周五 ? ?周六 ? ?周日" + "\r\n" + "\r\n" + "\r\n"; ? ? ? ? ? ? ? ? textBoxDemonstrate.Text += compute(year, month); ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public bool leap_Year(int year) ? ? ? ? { ? ? ? ? ? ? if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? ? ? ? ? ? ? ? return true; ? ? ? ? ? ? else ? ? ? ? ? ? ? ? return false; ? ? ? ? } ? ? ? ? public string compute(int year, int month) ? ? ? ? { ? ? ? ? ? ? int days1 = (year - 1) * 365; ? ? ? ? ? ? for (int i = 1; i < year; i++) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? if (leap_Year(i)) ? ? ? ? ? ? ? ? ? ? days1++; ? ? ? ? ? ? } ? ? ? ? ? ? int[] monthArray = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; ? ? ? ? ? ? if (leap_Year(year)) ? ? ? ? ? ? ? ? monthArray[1] = 29; ? ? ? ? ? ? int days2 = 0, monthDays = monthArray[month - 1]; ? ? ? ? ? ? for (int i = 0; i < month - 1; i++) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? days2 += monthArray[i]; ? ? ? ? ? ? } ? ? ? ? ? ? int days = days1 + days2; ? ? ? ? ? ? string strCalendar=""; ? ? ? ? ? ? for (int i = 0; i < days % 7; i++) ? ? ? ? ? ? ? ? strCalendar += " ? ? ? ?"; ? ? ? ? ? ? for(int i=1;i<monthDays+1;i++) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? if (i < 10) ? ? ? ? ? ? ? ? ? ? strCalendar += " " + i + " ? ? ?"; ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? strCalendar += Convert.ToString(i + " ? ? ?"); ? ? ? ? ? ? ? ? if ((i+ days ?% 7) % 7 == 0) ? ? ? ? ? ? ? ? ? ? strCalendar += "\r\n"+"\r\n" + "\r\n"; ? ? ? ? ? ? } ? ? ? ? ? ? return strCalendar; ? ? ? ? } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#實(shí)現(xiàn)文件上傳與下載功能實(shí)例
本篇文章主要介紹了C#實(shí)現(xiàn)文件上傳與下載,這里整理了詳細(xì)的代碼,有需要的小伙伴可以參考下。2016-12-12C#使用DateTime.Now靜態(tài)屬性動(dòng)態(tài)獲得系統(tǒng)當(dāng)前日期和時(shí)間
本文主要介紹了C#使用DateTime.Now靜態(tài)屬性動(dòng)態(tài)獲得系統(tǒng)當(dāng)前日期和時(shí)間,DateTime結(jié)構(gòu)的Now靜態(tài)屬性只是得到一個(gè)系統(tǒng)時(shí)間對(duì)象,該時(shí)間對(duì)象不會(huì)隨著系統(tǒng)時(shí)間的變化而變化,如果要?jiǎng)討B(tài)顯示系統(tǒng)時(shí)間,可以使用計(jì)時(shí)器間隔地獲取系統(tǒng)時(shí)間對(duì)象并顯示,感興趣的可以了解一下2024-01-01C# PaddleDetection yolo實(shí)現(xiàn)印章檢測(cè)
這篇文章主要為大家詳細(xì)介紹了C#如何結(jié)合PaddleDetection yolo實(shí)現(xiàn)印章檢測(cè),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-11-11Unity的IFilterBuildAssemblies實(shí)用案例深入解析
這篇文章主要為大家介紹了Unity的IFilterBuildAssemblies實(shí)用案例深入解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05C#實(shí)現(xiàn)json格式數(shù)據(jù)解析功能的方法詳解
這篇文章主要介紹了C#實(shí)現(xiàn)json格式數(shù)據(jù)解析功能的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了C#解析json格式數(shù)據(jù)的具體操作步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-12-12C#實(shí)現(xiàn)將DataTable內(nèi)容輸出到Excel表格的方法
這篇文章主要介紹了C#實(shí)現(xiàn)將DataTable內(nèi)容輸出到Excel表格的方法,較為詳細(xì)的分析了C#基于DataTable保存Excel數(shù)據(jù)的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08