begin process at 2010 02 10 05:46:03
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

.NET

 > HEURE EN TEMPS RÉEL

HEURE EN TEMPS RÉEL


 Information sur la source

Note :
8 / 10 - par 1 personne
8,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :.NET Source .NET ( DotNet ) Classé sous :heure, temps, réel Niveau :Initié Date de création :24/09/2004 Vu :8 591

Auteur : gdupasqu

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Ce code affiche l'heure dans un "form" en temps réel. Deux thread sont crées :

1) Le "form"

2) Un thread appelé time Thread qui calcule l'heure, dort une seconde calcule l'heure, dort une seconde .... (en boucle) A chaque fois que le thread calcule l'heure, il l'affiche dans la "form".

Source

  • using System;
  • using System.Drawing;
  • using System.Collections;
  • using System.ComponentModel;
  • using System.Windows.Forms;
  • using System.Data;
  • using System.Threading;
  • namespace MyTime
  • {
  • /// <summary>
  • /// Summary for MyTime
  • /// </summary>
  • public class MyForm : System.Windows.Forms.Form
  • {
  • //{{OBJ_DECLARATION(MyTime.MyForm)
  • protected System.Windows.Forms.Label timeLabel;
  • //}}OBJ_DECLARATION
  • private Thread timeThread;
  • public MyForm()
  • {
  • // Required for Visual Forms support
  • InitializeComponent();
  • // TODO: Add any constructor code after InitializeComponent call
  • }
  • /// <summary>
  • /// Clean up any resources being used.
  • /// </summary>
  • protected override void Dispose( bool disposing )
  • {
  • base.Dispose( disposing );
  • }
  • /// <summary>
  • /// Required method for Visual Forms support - do not modify
  • /// the contents between the //{{ ... //}} tags.
  • /// </summary>
  • private void InitializeComponent()
  • {
  • //{{OBJ_INSTANTIATION(MyTime.MyForm)
  • this.timeLabel = new System.Windows.Forms.Label();
  • //}}OBJ_INSTANTIATION
  • this.SuspendLayout();
  • this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  • //{{OBJ_PROPERTIES(MyTime.MyForm.timeLabel)
  • this.timeLabel.Location = new System.Drawing.Point(30, 30);
  • this.timeLabel.Size = new System.Drawing.Size(140, 40);
  • this.timeLabel.TabIndex = 0;
  • this.timeLabel.Font = new System.Drawing.Font("Modern", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(255)));
  • //}}OBJ_PROPERTIES
  • this.timeLabel.Text = this.returnTime();
  • //{{FORM_PROPERTIES(MyTime.MyForm)
  • this.ClientSize = new System.Drawing.Size(200, 100);
  • this.Font = new System.Drawing.Font("MS Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  • this.Controls.Add(this.timeLabel);
  • //}}FORM_PROPERTIES
  • this.Text = this.returnDate();
  • this.Name = "MyForm";
  • //this.Text = "MyForm";
  • this.ResumeLayout(false);
  • timeThread = new Thread(new ThreadStart(timeLive));
  • timeThread.Start();
  • }
  • string returnDate(){
  • string dateNow = null;
  • DateTime now = DateTime.Now;
  • dateNow = now.Day + "." + now.Month + "." + now.Year ;
  • return dateNow;
  • }
  • string returnTime(){
  • string timeNow = null;
  • int hour;
  • int minute;
  • int second;
  • string hS, mS, sS;
  • DateTime now = DateTime.Now;
  • hour = now.Hour;
  • minute = now.Minute;
  • second = now.Second;
  • if( hour < 10 )
  • hS = "0" + hour;
  • else
  • hS = "" + hour;
  • if( minute < 10)
  • mS = "0" + minute;
  • else
  • mS = "" + minute;
  • if( second < 10 )
  • sS = "0" + second;
  • else
  • sS = "" + second;
  • timeNow = hS + ":" + mS + ":" + sS ;
  • return timeNow;
  • }
  • private void timeLive()
  • {
  • while(true)
  • {
  • this.timeLabel.Text = this.returnTime();
  • Thread.Sleep(1000);
  • }
  • }
  • /// <summary>
  • /// The main entry point for the application.
  • /// </summary>
  • static void Main()
  • {
  • Application.Run(new MyForm());
  • }
  • }
  • }
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace MyTime
{

	/// <summary>
	/// Summary for MyTime
	/// </summary>
	public class MyForm : System.Windows.Forms.Form
	{
	

		//{{OBJ_DECLARATION(MyTime.MyForm)
		protected System.Windows.Forms.Label timeLabel;
		//}}OBJ_DECLARATION
		
		private Thread timeThread;
	
		public MyForm()
		{
		// Required for Visual Forms support
			InitializeComponent();

		// TODO: Add any constructor code after InitializeComponent call
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		/// <summary>
		/// Required method for Visual Forms support - do not modify
		/// the contents between the //{{ ... //}} tags.
		/// </summary>
		private void InitializeComponent()
		{			
			//{{OBJ_INSTANTIATION(MyTime.MyForm)
			this.timeLabel = new System.Windows.Forms.Label();
			//}}OBJ_INSTANTIATION
			
			this.SuspendLayout();
						
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			
			//{{OBJ_PROPERTIES(MyTime.MyForm.timeLabel)
			this.timeLabel.Location = new System.Drawing.Point(30, 30);
			this.timeLabel.Size = new System.Drawing.Size(140, 40);
			this.timeLabel.TabIndex = 0;
			this.timeLabel.Font = new System.Drawing.Font("Modern", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(255)));
			//}}OBJ_PROPERTIES
			
			this.timeLabel.Text = this.returnTime();

			//{{FORM_PROPERTIES(MyTime.MyForm)
			this.ClientSize = new System.Drawing.Size(200, 100);
			this.Font = new System.Drawing.Font("MS Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Controls.Add(this.timeLabel);
			//}}FORM_PROPERTIES
			
			this.Text = this.returnDate();
			
			this.Name = "MyForm";
			//this.Text = "MyForm"; 
			
			this.ResumeLayout(false); 
			
			
			timeThread = new Thread(new ThreadStart(timeLive));
			timeThread.Start();		
		}
		
		
		string returnDate(){
			string dateNow = null;
			DateTime now = DateTime.Now;
			dateNow = now.Day + "." + now.Month + "." + now.Year ;
			return dateNow;
		}
		
		
		string returnTime(){
			string timeNow = null;
			int hour;
			int minute;
			int second;
			string hS, mS, sS;

			DateTime now = DateTime.Now;
			hour = now.Hour;
			minute = now.Minute;
			second = now.Second;

			if( hour < 10 )
				hS = "0" + hour;
			else
				hS = "" + hour;
				
			if( minute < 10)
				mS = "0" + minute;
			else
				mS = "" + minute;
				
			if( second < 10 )
				sS = "0" + second;
			else 
				sS = "" + second;
			
			timeNow = hS + ":" + mS + ":" + sS ;			
			return timeNow;
		}
		
		private void timeLive()
		{
			while(true)
			{
				this.timeLabel.Text = this.returnTime(); 	
				Thread.Sleep(1000);
			}
		}
		

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		static void Main() 
		{

			Application.Run(new MyForm());
		}

	}
}



 Sources de la même categorie

Source avec Zip CHAT SERVER-CLIENT par abderrahmenbilog
Source avec Zip Source avec une capture Source .NET (Dotnet) SIMULATION DE CONSOLE POUR WINDOWS MOBILE par originalcompo
Source avec Zip Source .NET (Dotnet) BASE DE DONNÉES EN XML par DanMor498
Source avec Zip Source avec une capture Source .NET (Dotnet) SIMPLECONV - APPLICATION DE CONVERSION MONÉTAIRE AVEC TAUX E... par Jeffrey_
Source avec Zip Source .NET (Dotnet) TRAITEUR D'IMAGE (MINI) par ycyril

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture Source .NET (Dotnet) DIFFÉRENCE DE TEMPS, XML, POCKETPC / WINFORMS...... par Steph115
Source avec Zip Source avec une capture Source .NET (Dotnet) NETTOYEUR DE DOSSIERS par mahhoura
Source avec Zip Source avec une capture Source .NET (Dotnet) HORLOGE/ALARME NUMÉRIQUE par Bio3G
Source avec Zip Source avec une capture Source .NET (Dotnet) COMPTE À REBOURS par Azema
Source .NET (Dotnet) CLASSE DATE AVEC QUELQUES FONCTIONS par ricklekebekoi

Commentaires et avis

Commentaire de bucherb le 05/10/2004 10:19:17

C'est un peu beaucoup de faire une mise à jour toute les secondes je trouve :-/  J'avais fais le même système qui se met a jour toutes les minutes, et qui garde une précision redoutable lol

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

manipulation de DateTime [ par Thanos_the_yopper ] en fait, je voudrais récupérer l'heure exact ou à été exécuter un évenement , et vérifier qu'il s'est bien passé un certain laps de temps avec de pouv interval de temps en minuit [ par dhabasse ] Salut tout le mondej'espere qu'il aura quelq'un pour m'aider comme je le trouve toujour dans ce forum.avec deux DateTimePicker  dtp1 et dtp2 en format Output (temps réel) commande DOS [ par OSiRiSPaulux ] Salut tlm, je suis actuellement sur un projet de frontend pour un logiciel en ligne de commande sous DOS; je souhaiterai savoir s'il existe un composa Compteur de ligne temps réel [ par ricklekebekoi ] Apres toutes ces questions, vous aurez sur ce site un éventail complet des propriétés du richtextbox :pDonc, j'aimerais afficher les lignes a gauche d Création de jeu de stratégie temps réel recherche d'équipe [ par pvpnd8 ] Création de jeu de stratégie temps réel. Salut à tous je me présente Ecriture log temps réel [ par vantoora ] Bonjour,Voilà j'ai développé un petit programme qui fait une (ou plutôt) comparaison de plusieurs dossiers dans une arborescence quelconque dans un se Déclencher une fonction à un temps précis [ par bubbathemaster ] Bonjour,Je sais, c'est sans doute une question conne mais j'ai pas trouvé...Comment déclencher en C# un évènement à une heure précise de la journée et Comment généré une grille, (tableau) avec des chiffres qui change tout le temps de place? [ par MickTos74 ] Bonjour, J'aimerai savoir si quelqu'un peut m'aider en c#, cela est peut être dur à réaliser mais en fait pour un projet assez important pour mon bts APPLICATION DE GESTION D'UNE ECOLE EN C# [ par HAVELINO ] Salut Chers Tous,Je voudrais avoir une application que je pourrai readdapter pour monter une qui permet de gerrer une ecole-etudiants-professeurs-moye temps nécessaire pour effectuer un relocage d'un site web [ par 112345 ] Salut, je veux savoir à peu près le temps nécessaire pour effectuer un relocage d'un site web: relocage surtout niveau design avec ajout de séquences


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,452 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales