Ask User If Wants to Exit Program Using C#
In this article, I will show you how to ask if the user wants to exit programs using C#, let’s follow the code below
Step 1:
Design windows form application like this (see below image)

Step 2:
Source code for Exit Button click events:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace askingtoexitprogram
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dialog = MessageBox.Show("Are You Sure, You Want To Exit Program!", "INFORMATION", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dialog == DialogResult.Yes)
{
MessageBox.Show("Successfully Exit Program");
Application.Exit();
}
else
{
return;
}
}
}
}
Output:

Code Explanation:
This code explain how to ask user if want to exit program
Ask User If Wants to Exit Program Using C# Free Download Source code
Mark Jaylo
YTC: https://www.youtube.com/c/MarkTheProgrammer
You may visit our facebook page for more information, inquiries and comments.
Hire our team to do the project.