0
private void LeaveFromField(object sender, EventArgs e)
{          
    var item = (TabPage)sender;
    DialogResult result = MessageBox.Show(null, "Внимание", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

    if (result == DialogResult.No)
    {
       //
    }                
}

у object sender нет того, что могло бы отменить выход с вкладки, а в EventArgs e кроме стандартных методов для object вообще ничего нет. Как отменить переход с вкладки?

0

1 ответ 1

1

Решено. Повесил обработчик на сам контрол Tab а не на вкладки:

private void SelectTab(object sender, TabControlCancelEventArgs e)   
{       
    DialogResult result = MessageBox.Show
    (
        "Выйти?",
        "Внимание",
        MessageBoxButtons.YesNo,
        MessageBoxIcon.Error
    );
    if (result == DialogResult.No)
    {
        e.Cancel = true;
    }
    if (result == DialogResult.Yes)
    {
        Clear();
    }
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.