c#winforms,关注表单直到form.Close()

时间:2016-09-08 10:21:30

标签: c# forms winforms

我有winform app,它有主表单和日志表单。当显示记录表单时,我希望它具有焦点,直到它将被关闭。我试过了:

loggingForm = new LoggingForm();
loggingForm.FormClosing += loggingForm_FormClosing;
loggingForm.bOK.Click += bOK_Click;

loggingForm.Show();
loggingForm.Activate();
loggingForm.Focus();
loggingForm.TopMost = true;
loggingForm.TopMost = false;

void loggingForm_FormClosing(object sender, FormClosingEventArgs e)
{
    if (isValidPass)
        e.Cancel = false;
    else
        e.Cancel = true;
}

1 个答案:

答案 0 :(得分:2)

试试这个:

loggingForm.ShowDialog();