I am trying to create a DialogBox in C++ .NET with both an "OK" button and a "Cancel" Button.

I know how to just show a MessageBox with an "OK" button like this:

MessageBox::Show(this, "Message");

I am trying to create a DialogBox in C++ .NET with both an "OK" button and a "Cancel" Button.

I know how to just show a MessageBox with an "OK" button like this:

MessageBox::Show(this, "Message");

I have tried with this but the compiler says that MB_OKCANCEL is undeclared identifier:

MessageBox::Show(this, "Message", MB_OKCANCEL);

Something like this ...

MessageBox::Show(this, "OK to proceed?", "A caption here ...", MessageBoxButtons::OKCancel, MessageBoxIcon::Question);

Thank you. That worked well.
As it is my first time I use an OKCANCEL dialogbox, I might wonder how it will
be possible to tell if the user ex. pressed the OK button or the CANCEL button.

Ex:

if (OK is pressed)  //What will be written on this line for OK or CANCEL
{
    Action Here;
}

Thank you...

Something like this ...

MessageBox::Show(this, "OK to proceed?", "A caption here ...", MessageBoxButtons::OKCancel, MessageBoxIcon::Question);
System::Windows::Forms::DialogResult result = MessageBox::Show(this, "OK to proceed?", "A caption here ...", MessageBoxButtons::OKCancel, MessageBoxIcon::Question);

if(System::Windows::Forms::DialogResult::OK == result)
{
    // OK button
}
else 
{
   // System::Windows::Forms::DialogResult::Cancel == result
   // Cancel button
}

Thank you very much, that did work very well.

jennifer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.