📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string[] a = new string[50]{ "(GMT -12:00) Eniwetok, Kwajalein ","(GMT -11:00) Midway Island, Samoa ",
"(GMT -10:00) Hawaii ","(GMT -09:00) Alaska ","(GMT -08:00) Pacific Time (US and Canada); Tijuana" ,"(GMT -07:00) Arizona" ,
"(GMT -07:00) Mountain Time (US and Canada)" , "(GMT -06:00) Central Time (US and Canada)", "(GMT -06:00) Mexico City, Tegucigalpa" , "(GMT -06:00) Saskatchewan" ,"(GMT -05:00) Bogota, Lima" ,
"(GMT -05:00) Eastern Time (US and Canada)" , "(GMT -05:00) Indiana (East)", "(GMT -04:00) Atlantic Time (Canada)", "(GMT -04:00) Caracas, La Paz" ,
"(GMT -03:30) Newfoundland", "(GMT -03:00) Brasilia", " (GMT -03:00) Buenos Aires, Georgetown", "(GMT -02:00) Mid-Atlantic ", "(GMT -01:00) Azores, Cape Verde Is.",
"(GMT +00:00) Greenwich Mean Time; Dublin, Edinburgh, London, Lisbon "," (GMT +00:00) Monrovia, Casablanca", "(GMT +01:00) Berlin, Stockhold, Rome, Bern, Brussels, Vienna",
" (GMT +01:00) Paris, Madrid, Amsterdam" ,"(GMT +01:00) Prage, Warsaw, Budapest" , "(GMT +02:00) Athens, Helsinki, Istanbul ","(GMT +02:00) Cairo",
"(GMT +02:00) Eastern Europe", "(GMT +02:00) Harare, Pretoria","(GMT +02:00) Israel ",
" (GMT +03:00) Baghdad, Kuwait, Nairobi, Riyadh", "(GMT +03:00) Moscow, St. Petersburgh, Kazan, Volgograd",
"(GMT +03:00) Tehran ","(GMT +04:00) Abu Dhabi, Muscat, Tbilisi" ,"(GMT +04:30) Kab","(GMT +05:00) Islamabad, Karachi, Ekaterinburg, Tashkent",
"(GMT +05:30) Bombay, Calcutta, Madras, New Delhi, Colombo",
"(GMT +06:00) Almaty, Dhaka ", "(GMT +07:00) Bangkok, Jakarta, Hanoi" ,"(GMT +08:00) Beijing, Chongqing, Urumqi" ,
" (GMT +08:00) Hong Kong, Perth, Singapore, Taipei "," (GMT +09:00) Tokyo, Osaka, Sapporo, Seoul, Yakutsk",
"(GMT +09:30) Adelaide" , "(GMT +09:30) Darwin", "(GMT +10:00) Brisbane, Melbourne, Sydney" ,
"(GMT +10:00) Guam, Port Moresby, Vladivostok" ,"(GMT +10:00) Hobart" ,
"(GMT +11:00) Magadan, Solomon Is., New Caledonia", "(GMT +12:00) Fiji, Kamchatka, Marshall Is." ,"(GMT +12:00) Wellington, Auckland", };
foreach (string str1 in a)
comboBox2.Items.Add(str1);
this.comboBox2.SelectedIndex = 0;
numericUpDown2.Value = Int32.Parse(DateTime.Now.Hour.ToString());
numericUpDown4.Value = Int32.Parse(DateTime.Now.Minute.ToString());
numericUpDown3.Value = Int32.Parse(DateTime.Now.Second.ToString());
label2.Text = DateTime.Now.ToString("tt");
if (label2.Text == "下午")
{
radioButton2.Checked = true;
}
else
{ radioButton2.Checked = false;
}
if (label2.Text == "上午")
{
radioButton1.Checked = true;
}
else {
radioButton1.Checked = false;
}
this.comboBox1.SelectedIndex = Int32.Parse(DateTime.Now.Month.ToString())-1;
this.numericUpDown1.Value =Int32.Parse(DateTime.Now.Year.ToString());
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
int[] b = new int[12] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
string y = numericUpDown1.Value.ToString();
string m = b[comboBox1.SelectedIndex].ToString();
//string m = comboBox1.Text.();
string d = DateTime.Now.Day.ToString();
monthCalendar1.SetDate(Convert.ToDateTime(y +"-"+ m +"-"+d));
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
label1.Text = "Current Time Zone : "+comboBox2.Text;
if (comboBox2.SelectedIndex == 0 || comboBox2.SelectedIndex == 1 || comboBox2.SelectedIndex == 2 || comboBox2.SelectedIndex == 5 || comboBox2.SelectedIndex == 8 || comboBox2.SelectedIndex == 9 || comboBox2.SelectedIndex == 10 || comboBox2.SelectedIndex == 12 || comboBox2.SelectedIndex == 14 || comboBox2.SelectedIndex == 17 || comboBox2.SelectedIndex == 21 || comboBox2.SelectedIndex == 28 || comboBox2.SelectedIndex == 30 || comboBox2.SelectedIndex == 33 || comboBox2.SelectedIndex == 34 || comboBox2.SelectedIndex == 35 || comboBox2.SelectedIndex == 36 || comboBox2.SelectedIndex == 37 || comboBox2.SelectedIndex == 38 || comboBox2.SelectedIndex == 40 || comboBox2.SelectedIndex == 41 || comboBox2.SelectedIndex == 43 || comboBox2.SelectedIndex == 45 || comboBox2.SelectedIndex == 47 || comboBox2.SelectedIndex == 48)
{
checkBox1.Enabled = false;
}
else
{
checkBox1.Enabled = true;
}
Graphics g = pictureBox1.CreateGraphics();
if(comboBox2.SelectedIndex==1){g.DrawImage(pictureBox1.Image, -15, 0);}if (comboBox2.SelectedIndex == 0){g.DrawImage(pictureBox1.Image, 0, 0);}if (comboBox2.SelectedIndex == 2){ g.DrawImage(pictureBox1.Image, -30, 0);} if (comboBox2.SelectedIndex == 2){g.DrawImage(pictureBox1.Image, -45, 0);} if (comboBox2.SelectedIndex == 4){ g.DrawImage(pictureBox1.Image, -60, 0);}
if (comboBox2.SelectedIndex == 5 || comboBox2.SelectedIndex == 6) { g.DrawImage(pictureBox1.Image, -75, 0); } if (comboBox2.SelectedIndex == 7 || comboBox2.SelectedIndex == 8 || comboBox2.SelectedIndex == 9) { g.DrawImage(pictureBox1.Image, -90, 0); }
if (comboBox2.SelectedIndex == 10 || comboBox2.SelectedIndex == 11 || comboBox2.SelectedIndex == 12) { g.DrawImage(pictureBox1.Image, -105, 0); } if (comboBox2.SelectedIndex == 13 || comboBox2.SelectedIndex == 14) { g.DrawImage(pictureBox1.Image, -120, 0); }
if (comboBox2.SelectedIndex == 15) { g.DrawImage(pictureBox1.Image, -75, 0); } if (comboBox2.SelectedIndex == 16 || comboBox2.SelectedIndex == 17) { g.DrawImage(pictureBox1.Image, -135, 0); } if (comboBox2.SelectedIndex == 18) { g.DrawImage(pictureBox1.Image, -150, 0); } if (comboBox2.SelectedIndex == 19) { g.DrawImage(pictureBox1.Image, -165, 0); }
if (comboBox2.SelectedIndex == 20 || comboBox2.SelectedIndex == 21) { g.DrawImage(pictureBox1.Image, -180, 0); } if (comboBox2.SelectedIndex == 22||comboBox2.SelectedIndex == 23||comboBox2.SelectedIndex == 24) { g.DrawImage(pictureBox1.Image, -195, 0); }
if (comboBox2.SelectedIndex == 25 || comboBox2.SelectedIndex == 26 || comboBox2.SelectedIndex == 27 || comboBox2.SelectedIndex == 28 || comboBox2.SelectedIndex == 29) { g.DrawImage(pictureBox1.Image, -210, 0); } if (comboBox2.SelectedIndex == 30 || comboBox2.SelectedIndex == 31 || comboBox2.SelectedIndex == 32 ) { g.DrawImage(pictureBox1.Image, -225, 0); }
if (comboBox2.SelectedIndex == 33) { g.DrawImage(pictureBox1.Image, -240, 0); } if (comboBox2.SelectedIndex == 34) { g.DrawImage(pictureBox1.Image, -248, 0); } if (comboBox2.SelectedIndex == 35) { g.DrawImage(pictureBox1.Image, -255, 0); } if (comboBox2.SelectedIndex == 36) { g.DrawImage(pictureBox1.Image, -263, 0); } if (comboBox2.SelectedIndex == 37) { g.DrawImage(pictureBox1.Image, -270, 0); }
if (comboBox2.SelectedIndex == 38) { g.DrawImage(pictureBox1.Image, -285, 0); } if (comboBox2.SelectedIndex == 39 || comboBox2.SelectedIndex == 40) { g.DrawImage(pictureBox1.Image, -300, 0); } if (comboBox2.SelectedIndex == 41) { g.DrawImage(pictureBox1.Image, -315, 0); } if (comboBox2.SelectedIndex == 42 || comboBox2.SelectedIndex == 43) { g.DrawImage(pictureBox1.Image, -323, 0); }
if (comboBox2.SelectedIndex == 44 || comboBox2.SelectedIndex == 45 || comboBox2.SelectedIndex == 46) { g.DrawImage(pictureBox1.Image, 330, 0); } if (comboBox2.SelectedIndex == 47) { g.DrawImage(pictureBox1.Image, -345, 0); } if (comboBox2.SelectedIndex == 48 || comboBox2.SelectedIndex == 49 ) { g.DrawImage(pictureBox1.Image, 360, 0); }
}
private void button1_Click(object sender, EventArgs e)
{
int[] a = new int[50] {-720 ,-660 ,-600,540, -480 ,-420 ,-420, -360, -360 ,-360 ,-300, -300, -300 ,-240, -240 ,-210, -180, -180,-120, -060, +000, +000 ,+060, +060, +060, +120, +120, +120, +120,+120, +180 ,+180, +180, +240, +270,+300,
+330 ,+360, +420 ,+480 ,+480,+540, +570 ,+570 ,+600, +600 ,+600, +660 ,+720, +720};
int[] b = new int[12] {1,2,3,4,5,6,7,8,9,10,11,12 };
string m = "False";
string n = "True";
string[] s = new string[50] { m, m, m, n, n, m, n, n, m, m, m, n, m, n, m, n, n, m, n, n, n, m, n, n, n, n, n, n, m, n, m, n, n, m, m, m, m, m, m, n, m, m, n, m, n, m, n, m, m, n };
string ss = comboBox2.Text;
string message = "OK...\n\n" + "======================\n" + "Year=" + numericUpDown1.Value.ToString() + "\n" + "Month=" +b[comboBox1.SelectedIndex].ToString() + "\n" + "Day=" + monthCalendar1.SelectionStart.Day.ToString() + "\n" + "Hour=" + numericUpDown2.Value.ToString() + "\n" + "Minute=" + numericUpDown4.Value.ToString() + "\n" + "Second=" + numericUpDown3.Value.ToString() + "\n" + "TimeZone=" + ss + "\n" + "Offset from GMT=" + a[comboBox2.SelectedIndex] + "minutes\n" + "Auto daylight=" + s[comboBox2.SelectedIndex] + "\n" + "==========================="+"\n"+"(Time not saved)";
string caption = " Exercise 5";
DialogResult Result;
Result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
if (Result == DialogResult.OK)
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
int[] a = new int[50] {-720 ,-660 ,-600,540, -480 ,-420 ,-420, -360, -360 ,-360 ,-300, -300, -300 ,-240, -240 ,-210, -180, -180,-120, -060, +000, +000 ,+060, +060, +060, +120, +120, +120, +120,+120, +180 ,+180, +180, +240, +270,+300,
+330 ,+360, +420 ,+480 ,+480,+540, +570 ,+570 ,+600, +600 ,+600, +660 ,+720, +720};
int[] b = new int[12] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
string m = "False";
string n = "True";
string[] s = new string[50] { m, m, m, n, n, m, n, n, m, m, m, n, m, n, m, n, n, m, n, n, n, m, n, n, n, n, n, n, m, n, m, n, n, m, m, m, m, m, m, n, m, m, n, m, n, m, n, m, m, n };
string ss = comboBox2.Text;
string message = "OK...\n\n" + "======================\n" + "Year=" + numericUpDown1.Value.ToString() + "\n" + "Month=" + b[comboBox1.SelectedIndex].ToString() + "\n" + "Day=" + monthCalendar1.SelectionStart.Day.ToString() + "\n" + "Hour=" + numericUpDown2.Value.ToString() + "\n" + "Minute=" + numericUpDown4.Value.ToString() + "\n" + "Second=" + numericUpDown3.Value.ToString() + "\n" + "TimeZone=" + ss + "\n" + "Offset from GMT=" + a[comboBox2.SelectedIndex] + "minutes\n" + "Auto daylight=" + s[comboBox2.SelectedIndex] + "\n" + "===========================" + "\n" + "(Time not saved)";
string caption = " Exercise 5";
DialogResult Result;
Result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
if (Result == DialogResult.OK)
Application.Exit();
}
private void button3_Click(object sender, EventArgs e)
{
int[] a = new int[50] {-720 ,-660 ,-600,540, -480 ,-420 ,-420, -360, -360 ,-360 ,-300, -300, -300 ,-240, -240 ,-210, -180, -180,-120, -060, +000, +000 ,+060, +060, +060, +120, +120, +120, +120,+120, +180 ,+180, +180, +240, +270,+300,
+330 ,+360, +420 ,+480 ,+480,+540, +570 ,+570 ,+600, +600 ,+600, +660 ,+720, +720};
int[] b = new int[12] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
string m = "False";
string n = "True";
string[] s = new string[50] { m, m, m, n, n, m, n, n, m, m, m, n, m, n, m, n, n, m, n, n, n, m, n, n, n, n, n, n, m, n, m, n, n, m, m, m, m, m, m, n, m, m, n, m, n, m, n, m, m, n };
string ss = comboBox2.Text;
string message = "Applied\n\n" + "======================\n" + "Year=" + numericUpDown1.Value.ToString() + "\n" + "Month=" + b[comboBox1.SelectedIndex].ToString() + "\n" + "Day=" + monthCalendar1.SelectionStart.Day.ToString() + "\n" + "Hour=" + numericUpDown2.Value.ToString() + "\n" + "Minute=" + numericUpDown4.Value.ToString() + "\n" + "Second=" + numericUpDown3.Value.ToString() + "\n" + "TimeZone=" + ss + "\n" + "Offset from GMT=" + a[comboBox2.SelectedIndex] + "minutes\n" + "Auto daylight=" + s[comboBox2.SelectedIndex] + "\n" + "===========================" + "\n" + "(Time not saved)";
string caption = " Exercise 5";
DialogResult Result;
//MessageBox.Show (message,caption,MessageBoxButtons.OK,MessageBoxIcon.None,MessageBoxDefaultButton.Button1);
Result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
if (Result == DialogResult.Yes)
Application.Exit();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int[] b = new int[12] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
string y = numericUpDown1.Value.ToString();
string m = b[comboBox1.SelectedIndex].ToString();
//string m = comboBox1.Text.();
string d = DateTime.Now.Day.ToString();
monthCalendar1.SetDate(Convert.ToDateTime(y +"-"+ m +"-"+d));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -