Answer the question
In order to leave comments, you need to log in
How to correctly handle clicking the "Cancel" button in a dialog box?
There is a small code, below I throw its listing. It is necessary to make it so that when you press the "cancel" or "ok" button, the program displays a message about an incorrect value through MessageBox.Show.
int number;
string name;
MessageBoxIcon icon;
number = Int32.Parse(Interaction.InputBox("Введите число: ", "Число"));
switch (number)
{
case 1: //Если ввел 1
name = "Единица"; //Название числа
icon = MessageBoxIcon.Information;
break; // Завершение блока
case 2: //Если ввел 2
name = "Двойка"; //Название числа
icon = MessageBoxIcon.Information;
break; // Завершение блока
case 3: //Если ввел 3
name = "Тройка"; //Название числа
icon = MessageBoxIcon.Information;
break; // Завершение блока
case 4: //Если ввел 4
name = "Четверка"; //Название числа
icon = MessageBoxIcon.Information;
break; // Завершение блока
default:
name = "";
icon = MessageBoxIcon.Information;
break;
}
MessageBox.Show(name, "Число", MessageBoxButtons.OK, icon);
Answer the question
In order to leave comments, you need to log in
He asked, he answered. If someone is interested in the solution, I give it a little below:
MessageBoxIcon icon = MessageBoxIcon.Error;
question = Interaction.InputBox("Введите число: ", "Число");
if (question == "")
{
MessageBox.Show("Вы не ввели значение!", "Ошибка", MessageBoxButtons.OK, icon);
}
number = Int32.Parse(question);
I usually catch the status of any windows through MessageBoxResult and process all the input on a click on the submit. And somewhere at the top there is a common data object in which everything changes. A form is just buttons and handlers.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question