单击表单上的任意位置时如何激活表单?

发布于 2024-11-16 17:31:33 字数 227 浏览 6 评论 0原文

我的 C# 应用程序运行良好,并且在需要时始终保持领先。我面临和想要的是:

假设我的应用程序打开,另一个应用程序(比如记事本)也打开,与我的应用程序窗口半重叠。当我们单击记事本上的任意位置时,它就会被激活。而对于我的应用程序,我必须单击窗口的顶部栏才能将其激活。为什么会这样呢?我想让我的应用程序处于活动状态,并在用户单击表单上的任意位置而不仅仅是顶部栏时将其置于前面。

我需要设置或实施什么来实现这一目标?

MY C# app workd fine and stays on top whenever asked to. What I face and want is :

Suppose my app is open and another app (say Notepad) is also opened halfly overlapping my app window. When we click anywhere on Notepad, it gets activated. Whereas with my app, I got to click the top bar of the window to make it active. Why so ? I want to make my app active and bring to front when user clicks anywhere on the form and not just hte top bar.

What do I need to set or implement to accomplish this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情绪少女 2024-11-23 17:31:33

尝试这样做,在 Form1_MousClick 事件上放置此代码

bool top = this.TopMost;
this.TopMost = true;
this.TopMost = top;

Try to do that ,on Form1_MousClick Event put this Code

bool top = this.TopMost;
this.TopMost = true;
this.TopMost = top;
往日情怀 2024-11-23 17:31:33

没什么,如果您单击窗口上的任意位置,它就会获得焦点并成为最上面的窗口,除非另一个窗口“始终位于顶部”。

Nothing, if you click anywhere on a Window, it gets focus and becomes the topmost window, unless another window is 'Always on top'.

王权女流氓 2024-11-23 17:31:33

问题在于重写 WndProc。删除了一项不必要的声明,事情得到了解决。感谢大家的努力。

The problem was with overridding WndProc. One unnecessary statement was removed and things got solved out.Thanks to all of you for your efforts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文