How to make a window always stay on top in .Net?(如何使窗口始终保持在.Net 的顶部?)
问题描述
我有一个在另一个程序中运行宏的 C# winforms 应用程序.另一个程序会不断地弹出窗口,并且通常会让事情看起来很疯狂,因为没有更好的词.我想实现一个取消按钮来停止进程运行,但我似乎无法让窗口保持在顶部.如何在 C# 中执行此操作?
I have a C# winforms app that runs a macro in another program. The other program will continually pop up windows and generally make things look, for lack of a better word, crazy. I want to implement a cancel button that will stop the process from running, but I cannot seem to get the window to stay on top. How do I do this in C#?
我尝试过 TopMost = true;
,但其他程序不断在顶部弹出自己的窗口.有没有办法每 n 毫秒将我的窗口发送到顶部?
I have tried TopMost = true;
, but the other program keeps popping up its own windows over top. Is there a way to send my window to the top every n milliseconds?
我解决此问题的方法是添加一个系统托盘图标,该图标将通过双击它来取消该过程.系统托盘图标不会被掩盖.感谢所有回复的人.我阅读了关于为什么没有超级顶部"窗口的文章......它在逻辑上不起作用.
The way I solved this was by adding a system tray icon that will cancel the process by double-clicking on it. The system tray icon does no get covered up. Thank you to all who responded. I read the article on why there is not a 'super-on-top' window... it logically does not work.
推荐答案
Form.TopMost
将工作,除非其他程序正在创建最顶层的窗口.
Form.TopMost
will work unless the other program is creating topmost windows.
无法创建未被另一个进程的新顶层窗口覆盖的窗口.Raymond Chen解释了原因.
There is no way to create a window that is not covered by new topmost windows of another process. Raymond Chen explained why.
这篇关于如何使窗口始终保持在.Net 的顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使窗口始终保持在.Net 的顶部?


- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01