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 7440831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:54:45+00:00 2026-05-29T10:54:45+00:00

Two questions here, hope that is OK. First, and mainly, I am trying to

  • 0

Two questions here, hope that is OK.

First, and mainly, I am trying to prompt the user when they exit my application whether or not they really want to exit. My code is as follows:

private void exitToolStrip_Click(object sender, EventArgs e)
{
    DialogResult mBoxResult = MessageBox.Show("Would you like to exit the program?", "Exit Program", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    switch (mBoxResult)
    {
        case DialogResult.Yes:
            this.Close();
            break;
        case DialogResult.No:
            break;
    }
}

According to MSDN, I should be using MessageBoxResult mBoxResult rather than DialogResult mBoxResult.

I am using .NET Framework 3.5. I read here that pre-3.0 should use DialogResult, but if I’m using 3.5, shouldn’t MessageBoxResult work?

When I try to call it, I get

The type or namespace name MessageBoxResult could not be found (are
you missing a using directive or an assembly reference?).

However, it works fine when I use DialogResult. Why is this?

My second question is regarding this piece of code:

case DialogResult.No:
break;

If somebody hits the Cancel button on the dialog, would it be proper to put anything in there besides the break? Or will everything function fine without it?

  • 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-29T10:54:46+00:00Added an answer on May 29, 2026 at 10:54 am

    DialogResult is for WinForms. MessageBoxResult is for SilverLight.

    Just the break statement is fine for the No case. But using a switch statement is overkill here. if (response == yes) Close(); would suffice.

    Note however that this isn’t an ideal way to do what you want. What if the user clicks the close button on the window border, or presses ALT+F4? Instead, you should handle the FormClosing event:

    private void MyForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (MessageBox.Show("Would you like to exit the program?", "Exit Program", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            e.Cancel = true;
    }
    

    By setting e.Cancel to true, you cancel the closure of the form. By doing nothing, you allow the form to close.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Two questions here, second is a little more complicated than first. 1 - I
This is my first question here, so I hope that I am providing enough
This is my first question here on stackoverflow, so I hope that I am
it's my first question here and I hope that I'm doing it right. I
So two questions here: If I use <input type=button onclick=validate()> then the enter key
I have two questions here. How can I show the header of the pop
In my two recent questions here and here I laid out my problem a
There are two similar questions asked here and here but no adequate answers are
This is two questions in one, so here we go. I have a simple
if($err) $_SESSION['msg']['login-err'] = implode('<br />',$err); Three quick questions: Why use a two-dimensional array here?

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.