为什么我的表单出现在所有东西的后面? [英] Why does my form appear behind everything?

查看:25
本文介绍了为什么我的表单出现在所有东西的后面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,我需要在调用表单之前做一些初始工作,所以我禁用了应用程序框架设置,并在需要运行表单时调用 Application.Run(myForm) 编写了自己的 Main 函数.

I have a program where I need to do some initial work before calling the form, so I disabled the Application Framework setting and wrote my own Main function with a call to Application.Run(myForm) when it's time to run the form.

一切正常,没有问题,但现在在打开表单之前我需要一些其他服务.与其将所有代码添加到该程序中,不如将其全部移至其自己的可执行文件中.第二个程序可以编辑第一个程序将使用的文件,因此我需要第一个程序等待,以便它读取这些更改(如果进行更改).我想可以同样轻松地使用 Shell 函数,但出于各种原因,我正在创建自己的 Process 对象并通过它调用/等待它.

Everything was working fine, no problems, but now I have need of some other service before opening the form. Rather than add all that code to this program, it has all been moved into its own executable. This second program can edit files that the first program will use, so I need the first program to wait so that it will read up those changes (should they be made). I suppose could just as easily use the Shell function, but for various reasons I'm creating my own Process object and calling it/waiting on it through that.

无论如何,我在 Application.Run 调用之前的某个时间调用了第二个程序.轮到第一个程序,我可以成功地与第二个程序交互,完全没有问题.但是当它完成时,第一个程序的窗口隐藏在屏幕上的任何其他窗口后面.这不会在 XP 中发生,只会在 Vista 中发生(也许是 7,但我还没有确认).我已经尝试过手动强制表单出现在前面,最小化然后最大化,获得焦点等,但除非用户用鼠标手动点击它,否则不会将它带到前面.

Anyway, I make this call to the second program some time before the Application.Run call. The first program waits its turn, and I can interact with the second program successfully, no trouble at all. But when it's done, the window for the first program is hidden behind any other windows that are on the screen. This doesn't happen in XP, only in Vista (and maybe 7, but I haven't confirmed yet). I've already tried manually forcing the form to appear in front, minimize then maximize, get focus, etc, but nothing brings it to the front unless the user manually clicks on it with the mouse.

我做错了什么?为什么会出现这种行为?我知道这与等待可执行文件完成有关,因为如果我不强制第一个程序等待一切都很好(除了不等待).我可以通过在表单的 Load 事件中调用第二个程序来规避这个问题,但是我必须第二次读取文件以捕获更改而不是读取一次,而且它看起来也很糟糕,因为正在绘制表单当第二个程序坐在那里时,真的很慢.

What am I doing wrong? Why does this behavior occur? I know it has something to do with waiting for the executable to finish, because if I don't force the first program to wait everything is fine (other than it not waiting). I can circumvent the issue by calling the second program in the Load event of the form, but then I have to read the file a second time to catch the changes instead of reading it once, and it also looks bad because the form is being drawn really slowly while the second program is sitting there.

如果有人有任何意见,我将不胜感激.

If anyone has any input, I'd appreciate it.

推荐答案

这并不是您遇到这种行为的真正原因,但一个简单的解决方法是临时设置表单的 TopMost 属性设置为 True.然后,根据您想要的干扰程度,您可以在短时间内重置它或等待 MouseEnter 事件触发.

This isn't really an answer to why you're experiencing this behaviour, but a simple workaround would be to temporarily set the form's TopMost property to True in the load event. Then, depending on how intrusive you want that to be, you could either reset it under a short timer or wait for say the MouseEnter event to fire.

这篇关于为什么我的表单出现在所有东西的后面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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