begin process at 2008 05 17 04:24:53
1 173 904 membres
36 nouveaux aujourd'hui
13 973 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

COUNTDOWN


Information sur la source

Catégorie :Date & Heure Source .NET ( DotNet ) Classé sous : date, compteàrebours, timer, countdwon Niveau : Débutant Date de création : 26/06/2007 Date de mise à jour : 26/06/2007 11:30:52 Vu / téléchargé: 7 245 / 395

Note :
Aucune note

Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

Description

Voila, en fait je cherchais un petit compte à rebours tout simple pour calculer le temps restant avant l'achat d'une nouvelle voiture. N'ayant pas trouvé, j'ai développé ce dont j'avais besoin : un c-à-r simple.

Je l'ai customisé un peu au niveau du graphisme mais il reste de nombreuses améliorations possibles. Encore une fois, mon but n'est pas de faire une appli aux fonctions exhaustives.

Pour info, cette source a été développée sous SharpDevelop en VB.NET 2005.

Merci à celui (il se reconnaîtra) qui a posté la source sur la gestion des forms ovales...

Source

  • '
  • ' Created by SharpDevelop.
  • ' User: neo2k2
  • ' Date: 22.06.2007
  • ' Time: 10:12
  • '
  • ' To change this template use Tools | Options | Coding | Edit Standard Headers.
  • '
  • Imports System.Drawing
  • Imports System.Drawing.Drawing2D
  • Imports System.Collections
  • Imports System.ComponentModel
  • '
  • Public Partial Class MainForm
  • Public Sub New()
  • ' The Me.InitializeComponent call is required for Windows Forms designer support.
  • Me.InitializeComponent()
  • '
  • ' TODO : Add constructor code after InitializeComponents
  • '
  • End Sub
  • Dim I As Integer 'Inactive
  • Dim DepartX As Short 'Used to move form
  • Dim DepartY As Short 'Used to move form
  • Dim H As Integer 'Hours
  • Dim M As Integer 'Minutes
  • Dim S As Integer 'Seconds
  • Dim T As String 'Time
  • Dim MyError As String 'Error
  • 'Dim Resultat As Integer 'Value for countdown
  • Private Sub Form1Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  • Label1.Text = System.DateTime.Now.ToLongTimeString
  • End Sub
  • Private Sub Button1Click(ByVal sender As Object, ByVal e As EventArgs)
  • H = textBox1.Text
  • M = textBox2.Text
  • S = textBox3.Text
  • If H = 0 And M = 0 And S = 1 Then System.Windows.Forms.MessageBox.Show( "Seconds must be greater than 1 !" ) : Timer2.Stop
  • Timer2.Enabled = True
  • Timer2.Start
  • Me.Button1.Enabled = "False"
  • Me.Button2.Enabled = "True"
  • Me.Button2.Text = "stop"
  • End Sub
  • Private Sub Button2Click(ByVal sender As Object, ByVal e As EventArgs)
  • Me.Button1.Enabled = "True"
  • Me.Button2.Enabled = "False"
  • Timer2.Stop
  • Label2.Text = "00:00:00"
  • End Sub
  • Private Sub Button3Click(ByVal sender As Object, ByVal e As EventArgs)
  • Me.Close
  • End Sub
  • Sub Timer1Tick(ByVal sender As Object, ByVal e As EventArgs)
  • 'This timer is permanently active as it shows the system time
  • Label1.Text = System.DateTime.Now.ToLongTimeString
  • End Sub
  • Sub Timer2Tick(ByVal sender As Object, ByVal e As EventArgs)
  • 'Count down
  • S = S - 1
  • If S = 0 Then S = 60 : M = M - 1
  • If M = 0 Then M = 60 : H = H - 1
  • If H = 0 Then H = 24
  • 'Small errors management
  • If S > 60 OR M > 60 OR H > 24 Then System.Windows.Forms.MessageBox.Show( "Value does not exist !" )
  • T = TimeSerial(H, M, S)
  • Label2.Text = T
  • 'Plays a sound when countdown reaches 00:00:00
  • Dim Snd As New System.Media.SoundPlayer("C:\Windows\Media\tada.wav")
  • If T = "00:00:00" Then Timer2.Stop : System.Windows.Forms.MessageBox.Show( "Countdown reached !" ) : Me.Button2.Text = "reset" : Label2.Text = T : Snd.Play()
  • End Sub
  • End Class
'
' Created by SharpDevelop.
' User: neo2k2
' Date: 22.06.2007
' Time: 10:12
' 
' To change this template use Tools | Options | Coding | Edit Standard Headers.
'
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Collections
Imports System.ComponentModel
'
Public Partial Class MainForm
	Public Sub New()
		' The Me.InitializeComponent call is required for Windows Forms designer support.
		Me.InitializeComponent()
		
		'
		' TODO : Add constructor code after InitializeComponents
		'
	End Sub
	
    Dim I As Integer 'Inactive 
    Dim DepartX As Short 'Used to move form
    Dim DepartY As Short 'Used to move form
    Dim H As Integer 'Hours
    Dim M As Integer 'Minutes
    Dim S As Integer 'Seconds
    Dim T As String  'Time
    Dim MyError As String 'Error
    'Dim Resultat As Integer 'Value for countdown

    Private Sub Form1Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = System.DateTime.Now.ToLongTimeString
    End Sub

	Private Sub Button1Click(ByVal sender As Object, ByVal e As EventArgs)
		H = textBox1.Text
        M = textBox2.Text
        S = textBox3.Text
    If H = 0 And M = 0 And S = 1 Then System.Windows.Forms.MessageBox.Show( "Seconds must be greater than 1 !" ) : Timer2.Stop
        Timer2.Enabled = True
        Timer2.Start
        Me.Button1.Enabled = "False"
        Me.Button2.Enabled = "True"
        Me.Button2.Text = "stop"
	End Sub
		
	Private Sub Button2Click(ByVal sender As Object, ByVal e As EventArgs)
		Me.Button1.Enabled = "True"
		Me.Button2.Enabled = "False"
		Timer2.Stop
		Label2.Text = "00:00:00"
	End Sub
	
	Private	Sub Button3Click(ByVal sender As Object, ByVal e As EventArgs)
		Me.Close
	End Sub
	
	Sub Timer1Tick(ByVal sender As Object, ByVal e As EventArgs)
		'This timer is permanently active as it shows the system time
        Label1.Text = System.DateTime.Now.ToLongTimeString
	End Sub
	
	Sub Timer2Tick(ByVal sender As Object, ByVal e As EventArgs)
		'Count down
        S = S - 1
        If S = 0 Then S = 60 : M = M - 1
        If M = 0 Then M = 60 : H = H - 1
        If H = 0 Then H = 24
        
        'Small errors management
        If S > 60 OR M > 60 OR H > 24 Then System.Windows.Forms.MessageBox.Show( "Value does not exist !" )

        T = TimeSerial(H, M, S)
        Label2.Text = T

		'Plays a sound when countdown reaches 00:00:00
		Dim Snd As New System.Media.SoundPlayer("C:\Windows\Media\tada.wav")
				
        If T = "00:00:00" Then Timer2.Stop : System.Windows.Forms.MessageBox.Show( "Countdown reached !" ) : Me.Button2.Text = "reset" : Label2.Text = T : Snd.Play()
	End Sub
	
End Class

Conclusion

Quelques bugs à corriger :

Erreur due à la gestion du déplacement de la form (lors de la compilation uniquement, pas d'influence sur le fonctionnement)
- Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated. (BC42025)

Problème d'arrêt du timer si la valeur du c-à-re st de 1 secondes (I need help for this)
- lorsque la valeur est 1 sec. le timer continue à descendre

Le son
- je ne sais pas s'il marche, je l'ai seulement testé au boulot et on n'a pas de hauts-parleurs...
- il faudrait plutôt mettre l'emplacement sous forme AppPathName ou un truc du genre au lieu de C:\Windows\Media...
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

26 juin 2007 11:30:52 :
petite correction mineure du zip et ajout d'une capture d'écran...
  • signaler à un administrateur
    Commentaire de neo2k2 le 26/06/2007 11:24:17

    Je précise que le bug concernant le déplacement de la form n'apparaît qu'au moment de la compilation mais que le programme fonctionne parfaitement, je pense que cela est dû au fait que je sois sous SharpDevelopp...

  • signaler à un administrateur
    Commentaire de TeBeCo le 27/06/2007 13:07:13

    l'erreur est pas du a ScharpDevelopp mais a ton code apparement tu tentes d'utiliser un membre static depuis uen instance de classe alors que pour utiliser un membre static il faut specifier le nom de la classe :

    dim toto as tata
    toto.nonstatic()
    tata.static()

    alors que toi tu fait :
    toto.static

Ajouter un commentaire

Discussions en rapport avec ce code source

Appels d'offres

Pub



CalendriCode

Mai 2008
LMMJVSD
   1234
567891011
12131415161718
19202122232425
262728293031 

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS