Click here to Skip to main content
15,889,116 members
Articles / Programming Languages / C#

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

Rate me:
Please Sign up or sign in to vote.
3.58/5 (11 votes)
29 Jan 2007CPOL 54.8K   845   22   6
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:

C#
// 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)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generaltoo many buttons Pin
colin39919-Aug-09 10:14
colin39919-Aug-09 10:14 
QuestionUse it for...? Pin
zeltera29-Jan-07 21:36
zeltera29-Jan-07 21:36 
AnswerRe: Use it for...? Pin
Chris Johanson29-Jan-07 23:14
Chris Johanson29-Jan-07 23:14 
GeneralRe: Use it for...? Pin
Chris Johanson29-Jan-07 23:22
Chris Johanson29-Jan-07 23:22 
GeneralGood job Pin
aprenot29-Jan-07 13:05
aprenot29-Jan-07 13:05 
Succint and to the point. Thanks.


GeneralRe: Good job Pin
Jason McBurney29-Jan-07 13:34
Jason McBurney29-Jan-07 13:34 

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

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