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
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
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|