如何使表格保持在另一个之上 [英] How to make a form stay above another

查看:108
本文介绍了如何使表格保持在另一个之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的.NET应用程序中,如果某些任务需要一段时间告诉用户该程序仍在工作,则我将显示带有请稍候"消息的表单.这种形式必须在其自己的线程中运行,因为主线程是正在工作的线程,因此很忙. 我读到一个人可以使用Form.Owner来完成这项任务,但是我认为如果在以下表单上运行该表单就行不通不同的线程.

In my .NET application I am showing a form with a "Please wait" message if some task takes a while to tell the user that the program still works. This form has to run in it's own thread since the main thread is the one doing work and therefore busy. I read that one can use Form.Owner for this task, but I don't think that works if the forms run on different threads.

问题在于,等待表单可以隐藏在主表单的后面,在这种情况下,用户看不到它,也无法将它带到前面,因为它没有任务栏按钮(没有有一个).

The problem is that the wait form can be hidden behind the main form in which case the user couldn't see it and can't bring it to the front, since it has no task bar button (an it musn't have one).

我的问题是,是否可以让等待表单保持在主表单之上,而不使其成为AlwaysOnTop表单(它将保持在所有窗口之上)?

My question is if it is possible to let the wait form stay above the main form without making it an AlwaysOnTop form (which would stay above ALL windows)?

推荐答案

您可以使用您还可以使用以下代码:

You can also use the following code:

protected void SetZOrder(IntPtr bottom, IntPtr top) {
    const int flags = 0x0002 | 0x0001; 
    NativeMethods.SetWindowPos(bottom, top, 0, 0, 0, 0, flags);
}

bottom-主窗体的指针,top-等待窗体的指针.要获取指针,请使用Form.Handle属性.然后通过父表单的BeginInvoke方法调用SetZOrder.

bottom - the pointer of the main form, top - the pointer of the wait form. To get a pointer, use Form.Handle property. And call the SetZOrder via the BeginInvoke method of the parent form.

这篇关于如何使表格保持在另一个之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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