实现效果:
关键知识:
Environment类的NewLine属性 //用于获取为此环境定义的换行字符串,程序执行过程中方便对字符串进行换行
Environment类的EXIT方法 //用于快速退出窗体应用
DateTime对象的ToString方法 //使用指定日期格式化方式格式化字符串
实现代码:
private void Form1_Load(object sender, EventArgs e)
{
label1.Text += Environment.NewLine;
label1.Text += Environment.NewLine;
label1.Text += Environment.NewLine;
label1.Text += string.Format("{0}", DateTime.Now.ToString("F"));
label1.Text += Environment.NewLine;
label1.Text += string.Format("{0}", DateTime.Now.ToString("f"));
label1.Text += Environment.NewLine;
label1.Text += string.Format("{0}", DateTime.Now.ToString("D"));
label1.Text += Environment.NewLine;
label1.Text += string.Format("{0}", DateTime.Now.ToString("d"));
label1.Text += Environment.NewLine;
label1.Text += string.Format("{0}", DateTime.Now.ToString("G"));
label1.Text += Environment.NewLine;
label1.Text += string.Format("{0}", DateTime.Now.ToString("g"));
} private void button1_Click(object sender, EventArgs e)
{
Environment.Exit(0); //退出窗体应用
}