Click here to Skip to main content
Licence CPOL
First Posted 5 Oct 2008
Views 11,974
Downloads 76
Bookmarked 9 times

Display Confirmation message in Console application

By | 5 Oct 2008 | Article
Display Confirmation message in Console application

Introduction

This article is for explaining how you can display a confirmation message in a console application like what we are displaying in windows application.

Background

My aim is to help those people who don’t know how to implement it. It is pretty simple if you know how to do it.

Using the code

My main aim is to show how to implement confirmation message in console application. I am using a simple application which will ask for the confirmation “Do you want to continue?” If you press yes it will write “Yes” in the console and if you press “no” it will write “No” in the console.

First create a sample console application. Here the name I had given is Sample. Please refer the image below. Sample

Now right click on sample and select add reference. Please refer the image below.

Sample

From the add reference window select the tab .net. From the list select the option “System.Windows.Forms” and then press “Ok” button. Please refer the image below.

Sample

Reference will get added to your project as shown in the below image.

Sample

After this, add the following statement to the top for your project using System.Windows.Forms;

Now we can use the Message box as we are using it in a windows application. Please look at the sample code below. In the code sample I am using the MessageBox in the console application.

			
DialogResult ans = MessageBox.Show("Do you want to continue it?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (ans == DialogResult.Yes)
            {
                Console.Write("Yes");
            }
            else
            {
                Console.Write("No");
            }

		

Please refer the image below.

Sample

Please find the attached code for more details

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jans Mary Suncy

Software Developer
Capgemini India
India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 6 Oct 2008
Article Copyright 2008 by Jans Mary Suncy
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid