Üzerinde LogOutEvent ve form kapatma olayı olan bir form var. İşte ben onun formu kapanış özelliği taşıdığı belirtildi oturum kapatma düğmesini tıkladığımızdaKapatma olayı hem UserClosing hem de this.close üzerinde tetiklendi
private void MainGUI_FormClosing(Object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
DialogResult yesNo = MessageBox.Show(this, "Are you sure you want to Log Off?", "Log Off", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (yesNo == DialogResult.Yes)
{
Application.Exit();
}
else
{
e.Cancel = true;
}
}
}
Benim Sorun
private void btnLogOut_Click(object sender, EventArgs e)
{
DialogResult yesNo = MessageBox.Show(this, "Are you sure you want to Log Off?", "Log Off", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (yesNo == DialogResult.Yes)
{
new LoginForm();
this.Close();
string tst2 = Logout(AgentId, AgentPwd, ExtensionId);
if (tst2 == "TCF000")
MessageBox.Show(" Logout Success");
else
MessageBox.Show("Logout Failed");
}
}
Ve Form Kapanış Etkinliği, kodudur. Bunun için daha iyi bir kod önerilebilir mi?
'X' düğmesine tıkladığımda uygulamayı kapatmalı ve LogOut'u tıklattığımda geçerli pencereyi kapatmalı ve oturum açma formuna gitmeliyiz.
bunu çağırıyorsunuz.Close() bu nedenle yakın olayı tetikleyecek şekilde – V4Vendetta
@ V4Vendetta @Kragen @Marc Ama CloseReason.UserClose'un yalnızca X tıklandığında tetikleyici olacağını düşündüm. Ben hatalıydım. Kapanış için tetikleyici olaylar nelerdir ve ne zaman tetiklenir –
Bu size [Yardım edebilirim] olabilir (http://stackoverflow.com/questions/3631490/bug-in-formclosingeventargs-closereason) – V4Vendetta