欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)日歷效果

 更新時(shí)間:2022年06月13日 15:23:22   作者:?nonumb  
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)日歷效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(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)文章

最新評(píng)論