vb.net 如何使表单出现在所有其他窗口的顶部?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15411935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:44:13  来源:igfitidea点击:

How can I make a form appear on top of all other windows?

vb.netwinforms

提问by Kez

How can I make a form appear on top of everything on the desktop, not just forms within my application. I have spent ages Googling but only found snippets for C++ and older versions of Visual Studio which no longer work. I know the answer is out there, I must be looking for the wrong thing.

如何使表单出现在桌面上的所有内容之上,而不仅仅是我的应用程序中的表单。我花了很长时间在谷歌上搜索,但只找到了不再工作的 C++ 和旧版本的 Visual Studio 的片段。我知道答案就在那里,我一定是在寻找错误的东西。

Just to be clear - my project is created within Visual Studio 2012 and it is coded in Visual Basic.

需要说明的是 - 我的项目是在 Visual Studio 2012 中创建的,并且是在 Visual Basic 中编码的。

Thanks in advance.

提前致谢。

回答by SysDragon

As Steve said, this work as long as your app is the only one using it:

正如史蒂夫所说,只要您的应用程序是唯一使用它的人,这项工作就可以工作:

Me.TopMost = True

Its a property found in forms. If you are executing this outside a form, use the name of the form, for example Form1.TopMost = True.

它是在表单中找到的属性。如果您在表单外执行此操作,请使用表单的名称,例如Form1.TopMost = True

MSDN documentationand some info you may find interestingabout trying to make a window to be in top of "Top-Most" Windows.

MSDN 文档一些关于尝试使窗口位于“最顶层”窗口顶部可能会发现有趣的信息。

回答by user5351330

Setting TopMost to True makes it obsure other windows permanently. I found if you make it True then False, you'll bring the Form to the top so it is visible, yet other Forms can go over if they are selected.

将 TopMost 设置为 True 使其永久遮蔽其他窗口。我发现如果你把它设为 True 然后设为 False,你会将表格带到顶部以便它可见,但如果其他表格被选中,则可以跳过它们。

回答by R.Alonso

Me.TopMost = True

BUT in ACTIVATED (not in LOAD EVENT)

但是在 ACTIVATED 中(不在 LOAD EVENT 中)

Private Sub frm_Activated(sender As Object, e As EventArgs) Handles Me.Activated

    Me.TopMost = True
End Sub