将多张图片添加到imagelist中,并将其根据下标显示到按钮上,使用label显示当前时间(变化的),并用按钮
切换其暂停或者继续。修改字体的属性 颜色 保存 打开。
button需要绑定ImageList之后,才可以使用其ImageIndex属性;
时间有变化,应该通过计时器的方式去控制,DateTime.Now.ToLongDateString():显示当前的年月日;
DateTime.Now.ToLongTimeString():显示当前的时分秒。
fontDialog1、colorDialog1、saveDialog1、openDialog1对话框,都需要在工具箱中引入才可以使用。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace showDialog
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
labCurrentTime.Text =DateTime.Now.ToLongDateString()+ DateTime.Now.ToLongTimeString();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
//暂停显示当前的时间
private void button4_Click(object sender, EventArgs e)
{
if(flag.Text == "1")
{
timer1.Stop();
flag.Text = "0";
return;
}
if (flag.Text == "0")
{
timer1.Start();
flag.Text = "1";
return;
}
}
private void btnFont_Click(object sender, EventArgs e)
{
if(fontDialog1.ShowDialog() == DialogResult.OK)
{
string fontName = fontDialog1.Font.Name; //修改字体
float fontSize = fontDialog1.Font.Size; //修改大小
/*
* 修改字形
* */
FontStyle bold = 0, italic = 0, underline = 0, strikeout = 0;
if (fontDialog1.Font.Bold == true) //设置为粗体
{
bold = FontStyle.Bold;
}
if(fontDialog1.Font.Italic == true) //设置为斜体
{
italic = FontStyle.Italic;
}
if(fontDialog1.Font.Underline == true) //添加下划线
{
underline = FontStyle.Underline;
}
if(fontDialog1.Font.Strikeout == true) //添加删除线
{
strikeout = FontStyle.Strikeout;
}
//注意:设置的是文本框的Font属性,不要写错了name
this.textBox1.Font = new System.Drawing.Font(fontName, fontSize, ((System.Drawing.FontStyle)((((bold | italic)
| underline)
| strikeout))), System.Drawing.GraphicsUnit.Point, ((byte)(134)));
}
}
//修改背景色
private void button1_Click(object sender, EventArgs e)
{
if(colorDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.BackColor = colorDialog1.Color;
}
}
private void btnSave_Click(object sender, EventArgs e)
{
//指定文件保存格式,需严格按照该类型进行书写,否则会保存失败
saveFileDialog1.Filter = "文本文件(*.txt)|*.txt";
saveFileDialog1.ShowDialog();
}
private void btnOpen_Click(object sender, EventArgs e)
{
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
openFileDialog1.ShowDialog();
}
}
}
}