PDA

View Full Version : سوال: خروج از برنامه



meitti
دوشنبه 21 مرداد 1387, 21:16 عصر
سلام
اگه خواسته باشیم هنگام خروج از برنامه پیامی مبنی بر مطمئن بودن خروج از برنامه را بدهد چیکار باید کرد؟

jaza_sa
دوشنبه 21 مرداد 1387, 21:36 عصر
پیغامی رو که میخواید نشون بدید در رویدادهای FormClosing یا FormClosed قرار دهید .

hdv212
دوشنبه 21 مرداد 1387, 22:19 عصر
اگر در رویداد FormClosing این کار رو انجام بدید بهتره، چون حتی میتونید رویداد مورد نظر رو هم Cancel کنید.

e.Cancel = true;

Salar Ashgi
دوشنبه 21 مرداد 1387, 23:20 عصر
کد مورد نظر شما :



private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
DialogResult result = MessageBox.Show("Do Really Want to Exit ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
this.Hide();
}
else if (result == DialogResult.No)
{
this.Show();
}
}


موفق و پیروز باشید !!!

Amir Oveisi
دوشنبه 21 مرداد 1387, 23:48 عصر
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
DialogResult result = MessageBox.Show("Do Really Want to Exit ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
this.Hide();
}
else if (result == DialogResult.No)
{
this.Show();
}
}

این اون چیزی نیست که ایشون خواستن
درست ترش اینه:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{

DialogResult result = MessageBox.Show("Do Really Want to Exit ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result != DialogResult.Yes)
{
e.Cancel=true;
}
}