简体   繁体   English

C#总是像TopMost一样设置一个窗体,但是与其他窗口的交互总是可能的

[英]C# Setting a Form like always TopMost, but interaction is always possible with other windows

在此处输入图片说明

This is a screenshot of a Form . 这是Form的屏幕截图。 It's basically just those two lines at the top of a screen, when you hover them this little window pops up. 基本上只是屏幕顶部的这两行,当您将它们悬停时,会弹出这个小窗口。 I just wonder what these two lines might be. 我只是想知道这两行可能是什么。

I did not find any information on the internet on how to achieve something familiar. 我没有在互联网上找到有关如何实现熟悉的东西的任何信息。 I just want to know what idea is behind that, maybe some sample code would be nice to illustrate this idea. 我只想知道背后的想法,也许一些示例代码可以很好地说明这个想法。

Is this just some sort of custom window ? 这只是某种自定义窗口吗? Is WPF probably the way to go then? 那么WPF可能是要走的路吗? If so, how is it possible to set a Form always visible and usable (it is not required to click on the Form to get the focus to be able to interact with it) even though it can't be set as TopMost Form ? 如果是这样,即使无法将其设置为TopMost Form ,又如何设置一个始终可见且可用的Form (不需要单击Form以获得焦点即可与之交互)?

this.TopMost = true;

Because I can still interact with other windows, while the two lines custom form is still visible and overlaying all other windows. 因为我仍然可以与其他窗口进行交互,所以这两行自定义窗体仍然可见并且覆盖了所有其他窗口。 But under no circumstance this two lines custom form gets overlayed. 但是在任何情况下, 这两行自定义表单都不会重叠。 What idea is behind this custom Form ? 这个自定义表单背后的想法是什么?


Update: 更新:

After some additional research on the internet, it seems like the TopMost property doens't behave as you expect sometimes. 经过互联网上的一些其他研究之后,似乎TopMost属性有时并没有达到您的预期。 I just tested it a few more times and now it is behaving exactly the way I described I want it to be. 我只是对其进行了几次测试,现在它的行为完全符合我的描述。


Update on how this two lines Form work: 更新这两行表格的工作方式:

Imagine you have any window open in FullScreen. 假设您在“全屏”中打开了任何窗口。 But the two lines Form is at the top of your screen. 但是这两行窗体在屏幕顶部。 It hovers all other windows, but doesn't declare it's own space like an AppBar . 它会悬停所有其他窗口,但不会像AppBar那样声明它自己的空间。 The two lines Form gets never hidden, so there is no AutoHide involved. 两行Form永远不会隐藏,因此不涉及AutoHide It's just the window with " Screenshot region ", ...that pops up once the two lines Form get's hovered. 这只是带有“ 屏幕截图区域 ”的窗口,...悬停在窗体两行后会弹出。 Furthermore the two lines Form is bound to the top of the screen. 此外, 两行表格绑定到屏幕顶部。

It should work just fine with TopMost = true (in WinForms and in WPF too). TopMost = true它应该可以正常工作(在WinForms和WPF中也是如此)。 TopMost means window will be always displayed over any other windows without this flag set (so another topmost window might overlay your topmost window), including currently active window. TopMost意味着窗口将始终在没有设置此标志的情况下显示在任何其他窗口上(因此,另一个最顶层的窗口可能会覆盖您最顶层的窗口),包括当前活动的窗口。 So most likely what is on your screenshot is just topmost window with very small size aligned to the top of screen, which shows another window (or expands itself) on mouse over and hides that window (or shrinks itself) when mouse is out. 因此,屏幕快照上最有可能的是与屏幕顶部对齐的,尺寸很小的最上面的窗口,它在鼠标悬停时显示另一个窗口(或自行扩展),并在鼠标移出时隐藏该窗口(或自行收缩)。 I'm not an expert on WinForms, so if that doesn't work in some cases for you - you might find some information in google about why and when it doesn't work (for example some people claim it doesn't work when you run application from Visual Studio, so ensure you run it standalone while testing). 我不是WinForms的专家,所以如果在某些情况下对您不起作用-您可能会在Google中找到有关为什么以及何时不起作用的信息(例如,有人声称它在什么时候不起作用)您可以从Visual Studio运行应用程序,因此请确保在测试时独立运行该应用程序)。 But in general TopMost property should do just what you describe. 但是一般而言,TopMost属性应该按照您的描述进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM