如何将我的应用程序窗口置于最前面? [英] How can I bring my application window to the front?

查看:41
本文介绍了如何将我的应用程序窗口置于最前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将我的应用程序窗口置于最前面?例如我的应用需要注意什么.

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);

按下接受"按钮后,bool ready 设置为 true.

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

我工作得很好,但并非总是如此.

I works great but not always.

推荐答案

使用 Control.BringToFront:

myForm.BringToFront();

这篇关于如何将我的应用程序窗口置于最前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆