我怎样才能把我的应用程序窗口的前面?我的、应用程序、窗口

2023-09-02 11:47:53 作者:哭到全世界心碎

如何把我的应用程序窗口前?例如焕我的应用程序需要注意。

How to bring my application window to front? For example whan my app needs attention.

这是我个人的计划。我需要的功能。

This is for my personal program. I need that functionality.

这是我得到了什么。但它的不可以工作100%倍。

This is what I got. But it's NOT working 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 background worker.

BringToFrontToEnterCaptha();
while (!ready)
{
    Thread.Sleep(100);
}
BringToBackAfterEnterCaptha();
Thread.Sleep(300);

和之后pressing接受按钮布尔准备设置为true。

And after pressing "Accept" button bool ready is set to true.

我的伟大工程,但并非总是如此。

I works great but not always.

推荐答案

使用Control.BringToFront:

myForm.BringToFront();