Click here to Skip to main content
Licence CPOL
First Posted 29 Jan 2007
Views 26,861
Downloads 167
Bookmarked 22 times

MemoryBox: A Yes/No/Yes to all/No to all Dialog for C#

By | 29 Jan 2007 | Article
MemoryBox is a Yes/No/Yes to all/No to all dialog with a similar implementation to the standard Windows MessageBox.

Introduction

MemoryBox is a simple to use MessageBox-style dialog with memory functionality. It has "Yes to All" and "No to All" options like many file dialogs, and can be used in many operations.

Sample screenshot

Implementing

First, you must add the MemoryBox to your project. This is done by using the Add Existing Item option in your project navigator. The source file you need is included in the MemoryBox demo, called "MemoryBox.cs".

MemoryBox should be declared and constructed outside of the loop in which you wish to use the MemoryBox, as shown in the example below:

// Memory box is declared before the loop
MemoryBox memoryBox = new MemoryBox();
// Loop 5 times, counting the yeses and noes.
for (int i = 0; i < 5; i++)
{
    MemoryBoxResult result = memoryBox.ShowMemoryDialog("This demo was " + 
       "written by Chris Johanson of Twin Rose " + 
       "Software.\r\nYou will be asked 5 times a yes or no, " + 
       "and given a running total.\r\n", "Demo Memory Box");
    if (result == MemoryBoxResult.Cancel)
        break;
    if (result == MemoryBoxResult.Yes || result == MemoryBoxResult.YesToAll)
    {
        yesCount++;
    }
    if (result == MemoryBoxResult.No || result == MemoryBoxResult.NoToAll)
    {
        noCount++;
    }
    label1.Text = "Yes: " + yesCount + " No: " + noCount;
}

That should do it! If you have any comments, questions, or suggestions, I would love to hear them!

License

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

About the Author

Chris Johanson



United States United States

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
Generaltoo many buttons Pinmembercolin39910:14 19 Aug '09  
QuestionUse it for...? Pinmemberzeltera21:36 29 Jan '07  
AnswerRe: Use it for...? PinmemberChris Johanson23:14 29 Jan '07  
GeneralRe: Use it for...? PinmemberChris Johanson23:22 29 Jan '07  
GeneralGood job Pinmemberaprenot13:05 29 Jan '07  
GeneralRe: Good job PinmemberJason McBurney13:34 29 Jan '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 29 Jan 2007
Article Copyright 2007 by Chris Johanson
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid