65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.58/5 (11 votes)

Jan 29, 2007

CPOL
viewsIcon

55313

downloadIcon

850

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!