G
ginguene
Its supposed to be a very simple program, with a class to display the
updated current time every second (CAnalogTime) inside a Label in my
form, using ElapsedEventHandler from System.Timers;
The event is working, because the displaybox will show up every second
like requested.
Although the label (which i was able to initialize with a value), wont
update itself in this event.
Any ideas?
Thanx
--------------------------
public class CAnalogTime
{
public System.Timers.Timer myTimer;
public MainForm myForm;
public CAnalogTime( MainForm inForm)
{
myForm = inForm;
// There, the label will update normally ---->
myForm.label1.Text = "dfdstime";
myTimer = new System.Timers.Timer();
myTimer.Interval = 1000;
myTimer.Enabled = true;
myTimer.Elapsed += new ElapsedEventHandler(myForm.CheckInterval);
myTimer.Start();
}
}
public partial class MainForm
{
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public MainForm()
{
InitializeComponent();
CAnalogTime myAnalogClock = new CAnalogTime( this);
}
public void CheckInterval(object sender,
System.Timers.ElapsedEventArgs e)
{
// But here the label wont update
this.label1.Text = DateTime.Now.ToLongTimeString();
// And strangely, the textbox will display every second :
MessageBox.Show("toto");
}
}
--------------------------
updated current time every second (CAnalogTime) inside a Label in my
form, using ElapsedEventHandler from System.Timers;
The event is working, because the displaybox will show up every second
like requested.
Although the label (which i was able to initialize with a value), wont
update itself in this event.
Any ideas?
Thanx
--------------------------
public class CAnalogTime
{
public System.Timers.Timer myTimer;
public MainForm myForm;
public CAnalogTime( MainForm inForm)
{
myForm = inForm;
// There, the label will update normally ---->
myForm.label1.Text = "dfdstime";
myTimer = new System.Timers.Timer();
myTimer.Interval = 1000;
myTimer.Enabled = true;
myTimer.Elapsed += new ElapsedEventHandler(myForm.CheckInterval);
myTimer.Start();
}
}
public partial class MainForm
{
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public MainForm()
{
InitializeComponent();
CAnalogTime myAnalogClock = new CAnalogTime( this);
}
public void CheckInterval(object sender,
System.Timers.ElapsedEventArgs e)
{
// But here the label wont update
this.label1.Text = DateTime.Now.ToLongTimeString();
// And strangely, the textbox will display every second :
MessageBox.Show("toto");
}
}
--------------------------