Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - VB 2008 associare azione ad un cronometro Stopwatch
Forum - C# / VB.NET - VB 2008 associare azione ad un cronometro Stopwatch

Avatar
cbcup (Normal User)
Newbie


Messaggi: 17
Iscritto: 12/10/2010

Segnala al moderatore
Postato alle 14:08
Venerdì, 10/12/2010
Questo topic è stato chiuso dal moderatore

Salve, ho incominciato a studiare le funzioni di Stopwatch e mi domandavo come posso associare, ad un cronometro, dei comandi che si avviino quando nella label dei secondi e/o minuti sia visualizzato un dato tempo? Ho provato con 'if labelX.text = XX then' ma questo, pur non dandomi alcun errore, non ha effetto.
Allego il codice che ho trovato ed un po modificato del crono a cui vorrei associare i comandi lanciandoli da diversi bottoni (es. Button5)

Grazie, Carlo.

Codice sorgente - presumibilmente VB.NET

  1. Public Class Form1
  2.     Dim watch As New Stopwatch
  3.  
  4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  5.         Timer1.Enabled = True
  6.         watch.Start()
  7.     End Sub
  8.  
  9.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  10.         Timer1.Enabled = False
  11.         watch.Stop()
  12.     End Sub
  13.  
  14.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  15.         watch.Reset()
  16.         Label1.Text = "00"
  17.         Label2.Text = "00"
  18.         Label3.Text = "00"
  19.         Label4.Text = "000"
  20.     End Sub
  21.  
  22.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  23.         Label1.Text = String.Format("{0}", watch.Elapsed.Hours.ToString)
  24.         Label2.Text = String.Format("{0}", watch.Elapsed.Minutes.ToString)
  25.         Label3.Text = String.Format("{0}", watch.Elapsed.Seconds.ToString)
  26.         Label4.Text = String.Format("{0}", watch.Elapsed.Milliseconds.ToString)
  27.     End Sub
  28.  
  29.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  30.         Button3.PerformClick()
  31.         Button1.PerformClick()
  32.         If Label3.Text = 10 Then
  33.             K8090.Connect()
  34.             K8090.SwitchRelayOn(&HFF)
  35.             K8090.Disconnect()
  36.         End If
  37.     End Sub
  38.  
  39. End Class


PM
Avatar
HeDo (Founder Member)
Guru^2


Messaggi: 2765
Iscritto: 21/09/2007

Up
1
Down
V
Segnala al moderatore
Postato alle 15:21
Venerdì, 10/12/2010

la classe stopwatch server solo a misurare le peformances del codice in contesto di debugging o profiling, niente a che vedere con quello che vuoi fare te.

PM
Avatar
cbcup (Normal User)
Newbie


Messaggi: 17
Iscritto: 12/10/2010

Up
0
Down
V
Segnala al moderatore
Postato alle 16:13
Venerdì, 10/12/2010
Ho capito, grazie.
Bella fregatura.
Carlo.

PM