窗口损失焦点C#应用程序 [英] Window Losses Focus C# application

查看:80
本文介绍了窗口损失焦点C#应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我创建了一个条形码阅读器应用程序。在条形码阅读器的文本框中有等待输入的窗口,然后处理i / p并在列表框中显示成功消息。



一切正常,但有时自动窗口失去焦点(因为操作系统的后台/更新过程),条码阅读器的i / p无法到达文本框导致完全失败。



有什么办法,所以我可以编程那个窗口永远不会失去焦点吗?


SetForegroundWindow()可以帮忙吗?我该如何实现呢?



帮助赞赏!

Hello,
I have created an bar-code reader application. There is window which awaits for input in the text box from bar-code reader and then process the i/p and display the success message in List-box.

All is working fine, but some time automatically the window looses focus (because of background/updating processes of OS) and the i/p from bar-code reader cannot reach the text-box causing a complete failure.

Is there any way, so that i can program that window to never loose focus?

SetForegroundWindow() can it help? how can i implement this?

help appreciated!

推荐答案

您可以在表单中添加计时器并在Tick事件中将表单设置为前景窗口。 SetForegroundWindow()在以下文章中解释。



如何使用SetForegroundWindow()将窗口置于顶部[ ^ ]
You can add a timer to the form and in Tick event set the form as a foreground window. SetForegroundWindow() is explained in the following post.

How to bring window to top with SetForegroundWindow()[^]


你可以尝试离开事件



You could try the Leave event

private void txtTranUser1_Leave(object sender, EventArgs e)
       {
           this.txtTranUser1.Focus();
       }


这篇关于窗口损失焦点C#应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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