Accueil > > > HEURE EN TEMPS RÉEL
HEURE EN TEMPS RÉEL
Information sur la source
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
Commentaires et avis
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
Animation temps réel d'avatar 3D [ par zanzan ]
Bonjour Je cherche une API pour afficher un personnage 3d que je pourrais animer en temps réel, le tout sous c#. L'idée est de le faire réagir en fonc
Additionner les éléments d'une listbox - C# - [ par Dhazel ]
Bonjour, Je souhaiterais obtenir de l'aide concernant des listbox : Pour situer mon soucis je suis dans un projet Windows Form Visual 2005 en c#, Sur
|
Derniers Blogs
TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko [FRAMEWORK 4] LES TASKS ET LE THREAD UI[FRAMEWORK 4] LES TASKS ET LE THREAD UI par fathi
Je viens de passer quelques temps au TechDay's et j'ai pu voir pas mal de session intéressante. Par contre une chose m'a un peu étonné lors de certaines de ces sessions qui abordaient les améliorations du framework .NET (donc le 4.5) : en gros, bea...
Cliquez pour lire la suite de l'article par fathi WORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBEWORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBE par JeremyJeanson
Depuis déjà un an, je conseille vivement les utilisateurs de Workflow Foundation 3 à migrer vers la version 4. L'information qui va suivre ne devrait donc pas trop prendre au dépourvu les personnes qui m'ont suivi. Je profite de ce poste, pour faire le re...
Cliquez pour lire la suite de l'article par JeremyJeanson TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
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 Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.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 LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|