|
 |
|
ขอโค้ดที่เป็น นาฬิกาจับเวลาหน่อยครับ คือว่าผมจะเอาไปใช้ในการทำแบบทดสอบนะครับ |
|
 |
|
|
 |
 |
|
อันนี้ผมมีคนให้ผมมาครับลองดูนะ
Timer timer = new Timer();
Stopwatch sw = new Stopwatch();
public frmUsageTime()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(frmUsageTime_Loaded);
}
void frmUsageTime_Loaded(object sender, RoutedEventArgs e)
{
\\ เรียกให ้TimerStart
timer.Start();
sw.Start();
timer.Tick += new EventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
{
\\TODO: เมื่อถึงเวลาที่กำหนดจะใหท้ ำอะไร
string timestr = "";
string h = "";
string m = "";
string s = "";
TimeSpan timespan = sw.Elapsed;
h = timespan.Hours.ToString();
m = timespan.Minutes.ToString();
s = timespan.Seconds.ToString();
if (h.Length < 2)
h = "0" + timespan.Hours.ToString();
if (m.Length < 2)
m = "0" + timespan.Minutes.ToString();
if (s.Length < 2)
s = "0" + timespan.Seconds.ToString();
timestr = h + " : " + m + " : " + s;
lblTime.Content = timestr;
}
Page 1 of 1
http://
อันนี้อีกอัน
Option Explicit
' ตัวแปรในการนับเวลาถอยหลังทุกๆ 1 นาที
Dim CountOneMin As Long ' ให้เป็น Integer ได้หรือไม่ ... 55555+
Private Sub Form_Load()
' Run Time
lblTimeNow.Caption = "" ' แสดงเวลาปัจจุบัน
lblMinute.Caption = 1 ' ตั้งเวลาไว้ที่ ... นาที
lblCountDown.Caption = "" ' แสดงเวลาการนับถอยหลัง
' Timer จะถูกกระตุ้น (Trigger) การทำงานทุกๆ 1 วินาที (1000 millisecond)
Timer1.Interval = 1000
Timer1.Enabled = True
' ตั้งนับถอยหลัง 1 นาที (60 x 1000 ได้หน่วยนับมิลลิวินาที)
CountOneMin = 60000
End Sub
' ส่วนของ Timer จะถูกกระตุ้น (Trigger) การทำงานทุกๆ 1 วินาที
Private Sub Timer1_Timer()
' แสดงเวลาปัจจุบัน
lblTimeNow.Caption = Format(Time$, "hh:mm:ss AMPM")
' เริ่มการลดค่าครั้งละ 1 วินาที (1000 millisecond)
CountOneMin = CountOneMin - 1000
' ============================ แสดงผลเวลาการนับถอยหลัง =========================
' แสดงผลเวลาเป็นวินาที เช่น 59, 58, 57, ... ไปจนถึง 10 วินาที
If CountOneMin >= 10000 Then
' เวลาจะเป็น Millisecond เช่น 59000 ให้นับ 2 ตัวหน้าไว้เพื่อแสดงผล
lblCountDown.Caption = Val(lblMinute.Caption) - 1 & " : " & Mid(CountOneMin, 1, 2) & " นาที"
' น้อยกว่า 10 วินาที เช่น 9000 ... ให้เอาตัวหน้าสุดตัวเดียวเรียงต่อจาก 0 เช่น 09, 08, 07 ... 01
Else
lblCountDown.Caption = Val(lblMinute.Caption) - 1 & " : 0" & Left(CountOneMin, 1) & " นาที"
End If
' ========================================================================
' ตรวจสอบว่านับถอยหลังครบ 1 นาที (60000 millisecond) หรือไม่
' กรณีนี้ครบแล้ว
If CountOneMin = 0 Then
' ให้ตรวจสอบอีกว่านับเวลาครบตามจำนวนนาทีที่ตั้งไว้แล้วหรือไม่
' กรณีจริง ... แสดงว่าครบแล้ว
If Val(lblMinute.Caption) - 1 = 0 Then
lblMinute.Caption = Val(lblMinute.Caption) - 1
lblCountDown.Caption = "หมดเวลา/Logout Time"
' ปิดการทำงานของ Timer
Timer1.Enabled = False
MsgBox "หมดเวลาในการทำข้อสอบ.", vbOKOnly + vbExclamation, "หมดเวลา"
End
' ยังนับเวลาตามจำนวนนาทีที่ตั้งไว้ไม่ครบ
Else
' ทำการลดค่าเวลาลงไป 1 นาที เช่นเดิมตั้งไว้ 3 นาที ก็จะเหลือ 2 นาที แล้วเริ่มต้นกระบวนการนับเวลาถอยหลังอีกครั้ง
lblMinute.Caption = Val(lblMinute.Caption) - 1
' ให้ตั้งค่าการนับถอยหลังในทุกๆ 1 นาทีใหม่อีกครั้ง
CountOneMin = 60000
End If
End If
End Sub
|
 |
 |
 |
 |
Date :
2009-10-29 15:34:15 |
By :
pacus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือโค้ดตัวนี้
เป็นภาษาอะไรครับ
|
 |
 |
 |
 |
Date :
2009-10-29 16:34:18 |
By :
ting |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าจะเป็น C# .Net น่ะครับ
|
 |
 |
 |
 |
Date :
2009-10-29 21:43:32 |
By :
otomokung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รู้สึกข้างบน จะเป็น VB.Net นะครับ สังเกตจาก if ...then end if
|
 |
 |
 |
 |
Date :
2013-10-16 10:15:52 |
By :
maximumoflove |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|