我想diplay秒錶計時...使用Asp.Net C#...秒錶計時在Asp.Net
我reffer多線程,並在谷歌搜索也... ,但無法找到正確的代碼或解決方案.. 最讓我找到了解決方案,通過點擊都很難implemnt和一些didnt的工作......
我想創建秒錶像下面圖片..
在這啓動按鈕從00.00開始手錶,格式爲HH.MM.
並將按鈕的文本更改爲停止。 並通過點擊一遍,使其停止手錶.. ,然後保存了當時的數據庫,並在給定的文本框通過點擊重置重置時間至00:00顯示.... ..
怎麼能我做這些?
我沒有關於this..so需要一些代碼的任何想法...
OK下面是代碼和圖片,我試圖網站...
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Diagnostics;
public partial class Default5 : System.Web.UI.Page
{
private Stopwatch sw = new Stopwatch();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
if (Button3.Text == "start")
{
Timer1.Enabled = true;
sw.Start();
Button3.Text = "stop";
}
else
{
Timer1.Enabled = false;
sw.Stop();
Button3.Text = "start";
//TextBox1.Text = Label1.Text;
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
int hrs = sw.Elapsed.Hours;
//int hrs = "1;
int mins = sw.Elapsed.Minutes;
int secs = sw.Elapsed.Seconds;
Label1.Text = hrs + ":";
if (mins < 10)
Label1.Text += "0" + mins + ":";
else
Label1.Text += mins + ":";
if (secs < 10)
Label1.Text += "0" + secs;
else
Label1.Text += secs;
}
}
,筆譯項目中的代碼(這WELL廠)...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Stopwatch sw = new Stopwatch();
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "Start")
{
timer1.Enabled = true;
sw.Start();
button1.Text = "Stop";
}
else
{
timer1.Enabled = false;
sw.Stop();
button1.Text = "Start";
textBox1.Text = label1.Text;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
int hrs = sw.Elapsed.Hours, mins = sw.Elapsed.Minutes, secs = sw.Elapsed.Seconds;
label1.Text = hrs + ":";
if(mins <10)
label1.Text += "0" + mins + ":";
else
label1.Text += mins + ":";
if (secs < 10)
label1.Text += "0" + secs;
else
label1.Text += secs;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
在這兩種定時器間隔被設定在1000
在網站上,該時間不增加。它仍然是0:00:00 ...
你有在C#中的經驗嗎?你知道如何訪問數據庫嗎? – 2012-02-10 07:25:06
是的,我嘗試使用內置設施來實現它,但它在項目(創建新項目)中運行良好,不能在網站工作(創建新網站)。 – Dip 2012-02-10 10:44:52
如果您發佈的網站中的代碼不工作,以及某些細節不適用,那麼也許我們可以幫助:) – 2012-02-10 12:36:50