Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7624389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:57:02+00:00 2026-05-31T04:57:02+00:00

I am using this code but it does not work, what am I doing

  • 0

I am using this code but it does not work, what am I doing wrong?

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    if (MessageBox.Show("This will close down the whole application. Confirm?", "Close Application", MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        MessageBox.Show("The application has been closed successfully.", "Application Closed!", MessageBoxButtons.OK);
    }
    else
    {
        e.Cancel = true;
        this.Activate();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:57:04+00:00Added an answer on May 31, 2026 at 4:57 am

    I’ll guess that you copied this code from somewhere and forgot to actually subscribe the FormClosing event. Common trap in C#, VB.NET uses the Handles keyword to avoid mistakes like that. Select the form, click the lightning bolt icon in the Properties window and double-click FormClosing to add the code that subscribes the event.

    That said, it doesn’t actually make sense to write code like this. Events are for other code to get notifications, a class doesn’t have to listen to its own events. In Winforms, every event is triggered by a protected OnXxxx() method that you can override. You can cut and paste the code below and fall in the pit of success, it doesn’t require any extra code like the event subscription code to work. And best of all, it gives preference to custom event handlers first, the kind of code you don’t know about (yet) and ought to get the first shot at dealing with the notification.

        protected override void OnFormClosing(FormClosingEventArgs e) {
            base.OnFormClosing(e);
            if (!e.Cancel) {
                if (MessageBox.Show("Really?", "Close", MessageBoxButtons.YesNo) != DialogResult.Yes) {
                    e.Cancel = true;
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've tried using this code and this to make a random quote generator, but
i am using this code <a onclick=javascript:var t=setInterval(GetUpdates(5,ajaxResult),300);>GetUpdates</a> but getting the syntax error
I'm using following code but cannot return data from MySQL. This is the output:
I am using pseudo-code here, but this is in JavaScript. With the most efficient
I am using the BlockingQueue code posted in this question , but realized I
This is the example code, I'm using these functions for a program, but scanf
While using this code to serialize an object: public object Clone() { var serializer
Can someone kindly enlighten me why the following code of mine does not work?
Using this code to zip a folder and it works perfect on small files
Im using this code for mysql connection $con = mysql_connect(localhost:/var/lib/mysql/mysql.sock, abc , xyz); if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.