Bonjour,
Après plusieurs heures de recherche je ne parviens pas à afficher dans un label l'heure courante à la seconde près qui se met à jour au fil des secondes..

J'avais trouvé une source
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# 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());
# }
#
# }
# }
qui utilise un thread pour cela, mais j'ai une exception comme quoi je n'ai pas le droit de mettre à jour un label dans un thread différent..
Je suis donc bloqué.
Merci pour votre aide.