ควบคุมปิดหน้าต่าง ตรงกดปุ่มกากบาท

private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("คุณต้องการออกจากโปรแกรม ใช่หรือไม่...", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
e.Cancel = false; // ปิดไปเลย}else{
e.Cancel =
true; //มันจะยังไม่ปิด

}

}

เพิ่มเติมที่ปุ่ม Exit

private void btExit_Exit_Click(object sender, EventArgs e)
{
this.Close();//มันจะวิ่งไปที่ FormClosing

}

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้