Accueil > > > CHRONOMÈTRE SANS TIMER
CHRONOMÈTRE SANS TIMER
Information sur la source
Description
un simple chronomètre sans utiliser de timer à la place on utilise la classe System.Diagnostics.Stopwatch dans ce petit bout de code je démontre aussi la création et l'utilisation de contrôles créés au moment de l'éxécution : TextBox et Cursor pour utiliser cette source créer un nouveau projet avec un simple bouton "Button1"
Source
- Public Class Form1
-
- Dim textbox1 As New TextBox
-
- ''' <remarks>
- '''
- '''
- ''' Dim mystopwatch As New System.Diagnostics.Stopwatch
- '''
- ''' utilisation du code trouvé sur :
- ''' http://www.vbfrance.com/codes/NET2-MESURER-TEMPS-EXECUTION-METHODE_33782.aspx
- '''
- '''
- ''' </remarks>
- Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- textbox1 = Nothing
- End Sub
-
- Private Sub chrono()
- Dim mystopwatch As New System.Diagnostics.Stopwatch
-
- textbox1.Text = Now & vbCrLf
- mystopwatch.Start()
- MsgBox("OK to stop?", MsgBoxStyle.Information + MsgBoxStyle.SystemModal)
- textbox1.AppendText(mystopwatch.Elapsed.Days & " J-" & mystopwatch.Elapsed.Hours & " H-" & mystopwatch.Elapsed.Minutes & " M-" & mystopwatch.Elapsed.Seconds & " s-" & mystopwatch.Elapsed.Milliseconds & " m")
- mystopwatch = Nothing
- End Sub
-
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
- With Me
- .Text = Application.ProductName
- .Cursor = New Cursor(Application.StartupPath & "\finger.ico")
- .DesktopBounds = Rectangle.FromLTRB(10, 10, 200, 200)
- .FormBorderStyle = Windows.Forms.FormBorderStyle.SizableToolWindow
- .TopMost = False
- End With
- With textbox1
- .Parent = Me
- .Multiline = True
- .Height = (Me.Height - Me.Button1.Height) - 25
- .Width = Me.Width - 8
- .ScrollBars = ScrollBars.Both
- .WordWrap = False
- .UseWaitCursor = False
- .TabStop = True
- .Cursor = New Cursor(Application.StartupPath & "\pink256.ico")
- .Visible = True
- End With
- With Button1
- .Height = 20
- .Dock = DockStyle.Bottom
- .Cursor = Me.Cursor
- .Text = "Restart"
- .PerformClick()
- End With
-
- End Sub
-
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- chrono()
- End Sub
-
- Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
- With textbox1
- .Height = (Me.Height - Me.Button1.Height) - 25
- .Width = Me.Width - 8
- End With
- End Sub
- End Class
Public Class Form1
Dim textbox1 As New TextBox
''' <remarks>
'''
'''
''' Dim mystopwatch As New System.Diagnostics.Stopwatch
'''
''' utilisation du code trouvé sur :
''' http://www.vbfrance.com/codes/NET2-MESURER-TEMPS-EXECUTION-METHODE_33782.aspx
'''
'''
''' </remarks>
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
textbox1 = Nothing
End Sub
Private Sub chrono()
Dim mystopwatch As New System.Diagnostics.Stopwatch
textbox1.Text = Now & vbCrLf
mystopwatch.Start()
MsgBox("OK to stop?", MsgBoxStyle.Information + MsgBoxStyle.SystemModal)
textbox1.AppendText(mystopwatch.Elapsed.Days & " J-" & mystopwatch.Elapsed.Hours & " H-" & mystopwatch.Elapsed.Minutes & " M-" & mystopwatch.Elapsed.Seconds & " s-" & mystopwatch.Elapsed.Milliseconds & " m")
mystopwatch = Nothing
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me
.Text = Application.ProductName
.Cursor = New Cursor(Application.StartupPath & "\finger.ico")
.DesktopBounds = Rectangle.FromLTRB(10, 10, 200, 200)
.FormBorderStyle = Windows.Forms.FormBorderStyle.SizableToolWindow
.TopMost = False
End With
With textbox1
.Parent = Me
.Multiline = True
.Height = (Me.Height - Me.Button1.Height) - 25
.Width = Me.Width - 8
.ScrollBars = ScrollBars.Both
.WordWrap = False
.UseWaitCursor = False
.TabStop = True
.Cursor = New Cursor(Application.StartupPath & "\pink256.ico")
.Visible = True
End With
With Button1
.Height = 20
.Dock = DockStyle.Bottom
.Cursor = Me.Cursor
.Text = "Restart"
.PerformClick()
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
chrono()
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
With textbox1
.Height = (Me.Height - Me.Button1.Height) - 25
.Width = Me.Width - 8
End With
End Sub
End Class
Conclusion
il est très facile de créer des contrôles en code et de s'assurer qu'ils auront la taille désirée à l'execution
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Pb taille des "contrôles" en fct de la taille de police [ par Rom ]
Bonjour à tous,J'ai le problème suivant :J'ai une form sur laquelle sont disposées plusieurs images. Le fait de changer la taille de la polices de win
contrôles Active X réalisés en VB et utilisées avec VC++ [ par fredo ]
bonjour, je suis plutôt orienté C++ mais je souhaiterais utiliser dans mes applications des contrôles activeX réalisés avec VB.Le problème, c'est que
Cherche un composant qui peut contenir des contrôles [ par Yoda ]
Je cherche un activeX ou un composant qui peut contenir autant de controles que l'on veut. Le composant doit aussi pour faire défiler tous les contrôl
Non accès a tous les contrôles [ par VSt@r ]
Visual Basic ne veut pas m'afficher certains controle. Un copain m'a dis que c'était à cause de ma version et m'a dis qu'il y avait moyen de pirater l
variables et contrôles [ par Vladimir ]
Salut,Niveau débutantJ'aimerais savoir comment on fait pour faire fonctionner le petit exemple qui suit:3 boites de texte: b1, b2, b3une variable : aa
combiner treeview/listview [ par roby ]
Salut à tousQuelqu'un saurait-il comment on fait pour combiner un TreeView et un ListView, à la manière de l'explorateur Windows ?> Entre les deux
Ajout de contrôles [ par Xentor ]
Comment faire pour définir les évenements d'un contrôle que je viens de créer avec Controls.add ?
Une erreur au chargement qui m'ENERVE²!!!!!!! [ par Filou ]
Au lancement de mon projet, j'ouvre une boite de dlg qui demande le chemin d'accès au fichier mdb.Dans mon form, j'ai deux contrôles adodc où j'avais
insertion de contrôles pendant l'exécution [ par rodrigos ]
Est-il possible de rajouter des contrôles tels que des commandbutton sur une form pendant l'exécution d'un programme. Ceci pour créer un programme qui
la création des contrôles Active X [ par nadiakar ]
comment créer des contrôles Active X, des .ocx Merci
|
Derniers Blogs
TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Je m'y prends un peu tard je sais, mais bon je suis développeur web et donc hyper fainéant ! Toujours dans le cadre des technologies émergentes, ici HTML5, parce qu'on aime HTML5 chez Wyg , nous seront présent, le vieux ( Aurélien V.) et moi, pour pr...
Cliquez pour lire la suite de l'article par Gio [WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|