Instead of
_progress.Show();
try:
_progress.ShowDialog();
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.
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:
As you can see the main form still has its focus and not the new form. What I want is this:
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?
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.
Solution
Instead of
_progress.Show();
try:
_progress.ShowDialog();