.NET 中内置的桌面应用程序的强制焦点 [英] Forcing Focus for Desktop Applications built in .NET

查看:29
本文介绍了.NET 中内置的桌面应用程序的强制焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生产应用程序,我一直想强制关注它.有时用户会不小心点击表单,蓝色焦点窗口会变成灰色.我有一个每 30 秒触发一次的计时器,我想以编程方式将焦点返回给表单,以便它从灰色变回蓝色并带有焦点.我试过使用 .focus 事件和 .activecontrol 属性,但这些似乎都不起作用,我也没有看到任何其他可行的选项.当然有办法做到这一点,但对吗?我在 VB.Net 中使用 Visual Studio 2008.

I have a production application that I always want to force focus on. Sometimes the users will accidentally click off the form and the blue focused window will turn gray. I have a timer that fires every 30 seconds and I want to programatically give focus back to the form so that it goes from gray back to blue with focus. I've tried using the .focus event and the .activecontrol property but none of those seem to work and I'm not seeing any other viable options. Surely there is a way to do this, though right? I'm using Visual Studio 2008 in VB.Net.

请指教.

推荐答案

我很幸运使用这个属性,this.TopMost = true;

I have had good luck using the property, this.TopMost = true;

private void frmMain_Shown(object sender, EventArgs e)
{
// Make this form the active form and make it TopMost
this.ShowInTaskbar = false;
this.TopMost = true;
this.Focus();
this.BringToFront();
this.TopMost = false;
}

您可以尝试创建一个函数并从您的计时器代码中调用它.(抱歉,它是在 C# 中).

You can try making a function and calling it from your timer code. (Sorry it is in C#).

这篇关于.NET 中内置的桌面应用程序的强制焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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