1、C# 闹钟程序
Programmer: 雷玄
你是否在找这个资料,希望对你有帮助!
1. 改变窗体样式:
2. 添加背景图片
添加两个图片框, 用来关闭和最小化 窗体
3.移动窗体
int x;//坐标
int y;
bool isMove=false;//是否移动
//鼠标移动事件
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if(isMove)
2、//是否移动
{
this.Left += MousePosition.X - x;//窗体到屏幕左边的距离=鼠标的当前位置-起始位置
this.Top += MousePosition.Y - y;
x=MousePosition.X;
y=MousePosition.Y;
}
}
//鼠标按下的事件
private void Form1_MouseDo
3、wn(object sender, MouseEventArgs e)
{
isMove = true;
x = MousePosition.X;
y = MousePosition.Y;
}
//鼠标离开的事件
private void Form1_MouseLeave(object sender, EventArgs e)
{
isMove = false;
x = 0;
4、
y = 0;
}
//鼠标释放的事件。
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
isMove = false;
}
4.显示当前时间
a.添加时间控件
b.设置属性
c.把当前事件显示在label上
private void timer1_Tick(object sender, EventArgs e)
{
5、 label1.Text = System.DateTime.Now.ToString();
}
5.闹钟时间设置
a.把时间动态加载到 combox里
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i <= 60; i++)
{
comboBox2.Items.Add(i.ToString());//加载
comboBo
6、x3.Items.Add(i.ToString());
}
for (int i = 0; i <= 24; i++)
comboBox1.Items.Add(i.ToString());
comboBox1.SelectedIndex = 0;//默认显示第一列
comboBox2.SelectedIndex = 0;
comboBox3.SelectedIndex = 0;
}
b.时间设置 (butt
7、on按钮)
string colock;//设置的时间
private void button1_Click(object sender, EventArgs e)
{
colock = (comboBox1.Text + comboBox2.Text + comboBox3.Text).Trim() ;
}
6.设置好后 在timer控件里 ,写个判断语句
string temp;//把当前的时间 存在这个临时变量里
private void timer1_Tick(
8、object sender, EventArgs e)
{
temp=(System.DateTime.Now.Hour.ToString() +System.DateTime.Now.Minute.ToString()+
System.DateTime.Now.Second.ToString()).Trim();//当前时间 ,
label1.Text = System.DateTime.Now.ToString();//当前时间日期
if (colock == temp) //当前时间 ,是否与设置的时间相等
MessageBox.Show("时间到了,亲");
}
7.测试成功