How to bring the application window to the fore? For example, my application needs attention.
This is for my personal program. I need this functionality.
This is what I got. But it does NOT work 100% times.
public void BringToFrontToEnterCaptha() { if (InvokeRequired) { Invoke(new Action(BringToFrontToEnterCaptha)); } else { this.TopMost = true; this.Focus(); this.BringToFront(); this.textBox1.Focus(); this.textBox1.Text = string.Empty; System.Media.SystemSounds.Beep.Play(); } } public void BringToBackAfterEnterCaptha() { if (InvokeRequired) { Invoke(new Action(BringToBackAfterEnterCaptha)); } else { this.TopMost = false; } }
And I call them from the background worker.
BringToFrontToEnterCaptha(); while (!ready) { Thread.Sleep(100); } BringToBackAfterEnterCaptha(); Thread.Sleep(300);
And after clicking the Accept button, bool ready is true.
I work great, but not always.
Hooch Mar 12 2018-11-12T00: 00Z
source share