PDA

View Full Version : اجرا نمیشه: مشکل کجاست، آیا؟ :|



Raha_1991
پنج شنبه 20 تیر 1392, 11:20 صبح
برنامه ایست که درون یک فرم اگر ALT+F4 فشرده شد، جعبه پیغامی ظاهر شود که از کاربر سوال بپرسد و در صورت کلیک روی دکمه Yes از برنامه خارج شود.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
private void form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt == true && e.KeyCode == Keys.F4)
{ DialogResult dr = new DialogResult();
dr = MessageBox.Show("آیا میخواهیدخارج شوید؟", "خروج", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
Close();
else
e.Handled = true;

}
}
}

}

hamid_hr
پنج شنبه 20 تیر 1392, 11:28 صبح
اينو تو رويداد FormClosing بنويس درست ميشه
e.Cancel = true;
DialogResult dr = new DialogResult();
dr = MessageBox.Show("آیا میخواهیدخارج شوید؟", "خروج", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
e.Cancel = false;
else
e.Cancel = true;