Hi,
I am sorry for poor programming skill.
I have a form. Inside, I declared a global variable loginflag, the initial value is false, when users login, the value becomes true.But when I accessed this variable in other form, it always shows false.
Code://declare public bool loginflag=false;Code://update the loginflag to true private void btOK_Click(object sender, EventArgs e) { if (txtusers.Text == "") ....... else { LoginFlag = true; cSingleton.Instance.Main.Show(); } }Code://create singleton for accessing between forms public sealed class cSingleton { FMain _Main; FLogin _login; public cSingleton() { _Main = new FMain(); _login = new FLogin(); } static readonly cSingleton _Instance = new cSingleton(); public static cSingleton Instance { get { return _Instance; } } public FMain Main { get { return _Main; } } public FLogin Login { get { return _login; } } }What causes this? Thank you.Code://access loginflag from other form else { while (OpenComPort()) { if (dr == DialogResult.Cancel) { dr = DialogResult.Retry; return; } MessageBox.Show(cSingleton.Instance.Login.LoginFlag .ToString());//always false. problem here }




Reply With Quote