我有这个转换问题。
我有一个倒计时的秒表。然后将其显示在标签上,使其在标签(label1)上倒计时显示为“15:00:00”。
我还有另一次循环,每10秒循环一次,将秒表保存到另一个标签上(标签2)
那我怎么得到15:00:00?
我的表格中有3个文本框,第1个是小时,第2个是分钟,第3个是秒。 如果我在小时输入15,在分钟和秒输入00并按下button1,它会自动将15小时(15:00:00)转换为保存在我的数据库中的秒数,这样就不会保存15:00:00,而是保存TotalSeconds是54000秒。
当我的秒表启动时,它从数据库中获取54000并再次将其转换为label1中显示的15:00:00。
我可以将label2(“13:00:00”)的重叠时间转换为秒数,这会将转换后的值转换为另一个标签(现在是标签3)。?
Imports System
Imports System.Timers
Public Class ClientDashboard
Dim StopWatch As New Stopwatch
Dim CountDown As TimeSpan
Dim IsRunning As Boolean = False
Private Shared timer As System.Timers.Timer
Private Sub ClientDashboard_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Sets dashboard to right
Me.Size = New System.Drawing.Size(317, 900)
Dim x As Integer
Dim y As Integer
x = Screen.PrimaryScreen.WorkingArea.Width - 317
y = Screen.PrimaryScreen.WorkingArea.Height - Screen.PrimaryScreen.WorkingArea.Height
Me.Location = New Point(x, y)
'get time of user
cn = New ADODB.Connection
Call conDB()
cn.Open()
Dim rs As New ADODB.Recordset
rs.Open("select * from tb_registration where=st_acc_number= '" & id_lbl.Text & "'", cn, 0, 3)
iduser_lbl.Text = "'" & rs("st_name").Value & "'""'" & rs("st_lname").Value & "'"
UserTotal.Text = rs("st_totaltimeleft").Value
'Start stopwatch
StopWatch.Start()
synchroUpdate.Enabled = True
synchroUpdate.Start()
Dim numSecs As Integer
Integer.TryParse(UserTotal.Text, numSecs)
CountDown = TimeSpan.FromSeconds(numSecs)
End Sub
Private Sub synchro_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles synchro.Tick
End Sub
'--------------------->>>> Methord 2 <<<<----------------------
Private Sub DispElaps(ByVal ts As TimeSpan, ByVal lbl As Label)
lbl.Text = String.Format("{0:00} : {1:00} : {2:00}", _
Math.Floor(ts.TotalHours), _
ts.Minutes, _
ts.Seconds, _
ts.Milliseconds)
End Sub
Private Sub synchroUpdate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles synchroUpdate.Tick
synchroUpdate.Interval = 100
'If countDown > stpw.Elapsed Then
Dim elaps As TimeSpan = CountDown - StopWatch.Elapsed
DispElaps(elaps, TimerOutput)
'Else
'End If
End Sub
Private Sub DoEvent()
timer = New System.Timers.Timer(5000)
AddHandler timer.Elapsed, AddressOf AC
timer.AutoReset = True
timer.Enabled = True
End Sub
'Address of event
Private Sub SaveEvent2(ByVal sender As System.Object, ByVal e As EventArgs)
AutoUpdate_Button.PerformClick()
End Sub
'Event Handler
Private Sub AC()
If Me.InvokeRequired Then
Me.Invoke(New MethodInvoker(AddressOf AC))
Else
Me.AutoUpdate_Button.PerformClick()
End If
End Sub
Private Sub logoutBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles logoutBTN.Click
End Sub
End Sub
End Class
答案 0 :(得分:1)
您的代码似乎对标签使用了良好的名称,但您的问题尚未更新以对应。
尽管如此,您是否可以使用TimeSpan.TotalSeconds
类似于您已使用TimeSpan.TotalHours
的位置?