I have a public class that I store my two variables one for current time as string "tx" and the other for timer class "myT" as follow:
public static class MainVariables
{
private static string _tx = "";
public static string tx
{
get { return MainVariables ._tx; }
set { MainVariables ._tx = value; }
}
private static System.Windows.Forms.Timer _myT =
new System .Windows .Forms .Timer();
public static System .Windows .Forms .Timer myT
{
get { return MainVariables ._myT; }
set { MainVariables ._myT = value; }
}
}
after initializing windows component i have a method that initialize my components called "myInitialize" as follow:
public MainWindow()
{
InitializeComponent();
myInitialize();
}
in my initialize method I have the following code:
private void myInitialize()
{
ShowMeTheTime();
}
and here is the ShowMeTheTime method:
public void ShowMeTheTime()
{
MainVariables .myT .Enabled = true;
MainVariables .myT .Interval = 500;
MainVariables .myT .Tick += new EventHandler( ShoWTIME );
MainVariables .myT .Start();
}
public void ShoWTIME( object obj , EventArgs e )
{
MainVariables .tx = string .Empty;
MainVariables .tx = DateTime .Now .ToLongTimeString();
}
So here is the question. Why my variable "MainVariables .tx " in "ShoWTIME" method
does not get any value when the timer tick?
However, if I raplace the "MainVariables .tx" with a textbox1.Text the text property of textbox1 get value and show me the current time every second?
Yours SIncerely