Question

I have searched but not found or found but nothing has worked for me, hence this question. Following code is used to show a progress-form on top of my main form. This form has to have focus.

Code:

private ProgressForm _progress;

private void ShowProgress(string message)
{
    Enabled = false;
    _progress = new ProgressForm(message, this);
    _progress.Show();
}

The form is shown but it does not have focus, see below image:

Incorrect

As you can see the main form still has its focus and not the new form. What I want is this:

Correct

I have tried following methods, but neither of them worked:

_progress.BringToFront();
_progress.Focus();
_progress.Activate();

I have also tried these methods from within the constructor of the new form but this gave the same result. Does anyone have an idea how to solve this?

Edit:

I used the solution proposed in the answer by 'gnarlybracket', only had to switch to lines of code to make it work. Also important, I found out why ShowProgress was not focusing. I called the method from the form's Load event. If I call it from the form's Activated event, the new form is shown and had focus.

Was it helpful?

Solution

Instead of

_progress.Show();

try:

_progress.ShowDialog();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top