111,126
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication19
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll")]
private static extern bool Beep(int freq, int dur);
public Form1()
{
InitializeComponent();
label1.Text = "还剩01分10秒";
timer1.Interval = 1000;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
DateTime DT = DateTime.ParseExact(label1.Text, "还剩mm分ss秒", null);
DT = DT.AddSeconds(-1);
label1.Text = DT.ToString("还剩mm分ss秒");
if (DT.Minute == 0 && DT.Second == 0)
{
timer1.Enabled = false;
Beep(800, 300); // 机箱蜂鸣器发"di"的一声
}
}
}
}using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DateTime start;
Timer ti = new Timer();
private void Form1_Load(object sender, EventArgs e)
{
start = DateTime.Parse("00:00:01");//倒计时开始时间
calculagraph(500);//假设500毫秒跳表一次
}
private void calculagraph(int interval)
{
ti.Interval = interval;
ti.Tick += new EventHandler(ti_Tick);
ti.Start();
}
[DllImport("kernel32.dll")]
public static extern bool Beep(int f, int d);
void ti_Tick(object sender, EventArgs e)
{
Timer ti1 = sender as Timer;
start = start.AddMilliseconds(-ti.Interval);
textBox1.Text = start.ToString("mm:ss:ffff");
if (textBox1.Text =="00:00:0000")
{
ti.Stop();
//MessageBox.Show("时间到");
Beep(800,3000);
}
}
}
}