Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
29 Jan 2007 1  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here