M
Marcus Kwok
I have a form that I display using ShowDialog() with an OK button and a
Cancel button, and I have set the buttons' DialogResult properties using
the designer. When the user clicks on OK, I call a method to check the
values they typed in some TextBoxes, and if they entered invalid data, I
display a MessageBox telling them what they did wrong. However, after
the MessageBox closes, the dialog also closes so they are not able to go
back and change their data.
I can not check the values until after they click on OK because I have
multiple TextBoxes that they must fill in (though they can be filled in
any order), and the values in each box depend on what has been entered
into the other boxes, so I do not want to prematurely tell them their
data is invalid if they haven't finished entering everything yet.
How do I stop the dialog window from closing? I suppose I could remove
the DialogResult property from the button and set it
explicitly/programmatically if all the checks are successful, but I
would rather keep the property set on the button if possible.
I am using Managed C++ (Visual Studio .NET 2003).
A simplified version of my code:
System::Void button_ok_Click(System::Object * sender, System::EventArgs * e)
{
if (!valid_data()) {
MessageBox::Show(S"Error!");
// What to put here to prevent window from closing?
}
}
Cancel button, and I have set the buttons' DialogResult properties using
the designer. When the user clicks on OK, I call a method to check the
values they typed in some TextBoxes, and if they entered invalid data, I
display a MessageBox telling them what they did wrong. However, after
the MessageBox closes, the dialog also closes so they are not able to go
back and change their data.
I can not check the values until after they click on OK because I have
multiple TextBoxes that they must fill in (though they can be filled in
any order), and the values in each box depend on what has been entered
into the other boxes, so I do not want to prematurely tell them their
data is invalid if they haven't finished entering everything yet.
How do I stop the dialog window from closing? I suppose I could remove
the DialogResult property from the button and set it
explicitly/programmatically if all the checks are successful, but I
would rather keep the property set on the button if possible.
I am using Managed C++ (Visual Studio .NET 2003).
A simplified version of my code:
System::Void button_ok_Click(System::Object * sender, System::EventArgs * e)
{
if (!valid_data()) {
MessageBox::Show(S"Error!");
// What to put here to prevent window from closing?
}
}