问题描述
我有一个在另一个程序中运行宏的 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 的顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!