如何使我的 Windows 窗体应用程序紧贴屏幕边缘?
任何人都知道如何让您的 .net windows 窗体应用程序像 Winamp 一样粘性/活泼,以便它捕捉到屏幕边缘?
目标框架是使用 VS08 用 C# 编写的 .NET 2.0 Windows Form。 我希望将此功能添加到自定义用户控件中,但我认为更多的人会受益于针对应用程序及其主窗体的描述。
谢谢。
Anyone out there know how to make your .net windows form app sticky/snappy like Winamp so it snaps to the edges of the screen?
The target framework would be .NET 2.0 Windows Form written in C#, using VS08. I am looking to add this functionality to a custom user control, but I figured more people would benefit from having it described for the application and its main form.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这工作得很好,可以在多个显示器上工作,观察任务栏:
This worked pretty well, works on multiple monitors, observes the taskbar:
接受的答案仅在完成拖动后捕捉窗口,而我希望表单在拖动时连续捕捉到屏幕边缘。 这是我的解决方案,大致基于 Paint.NET 源代码 :
它看起来像这样:
The accepted answer only snaps the window after finishing the drag, whereas I wanted the form to continuously snap to the screen edges while dragging. Here's my solution, loosely based off the Paint.NET source code:
And here's what it looks like:
只需检索您所在显示器的当前像素高度/宽度...
如何确定当前光标位置的活动监视器
...并处理表单的位置更改/移动事件。 当您进入其中时,假设边缘(主窗体的 Location.Left + 窗体宽度)或高度(主窗体的 Location.Top + 窗体高度)大约 25 像素,然后继续设置 .Left 和 .Top 属性以便您的应用程序“停靠”在角落里。
编辑:另一注意事项 - 当您实际执行“捕捉”时,您可能还需要将光标位置移动相对距离,以使其保持在窗口栏上的同一点上。 否则,当 MouseMove 和表单位置更改事件相互对抗时,您的表单可能会成为光标位置和“snappy”功能之间的一个巨大乒乓球。
Just retrieve the current pixel height/width of the monitor you're on...
How to determine active monitor of the current cursor location
... and process the location changed/moved events for the form. When you get within, say 25 pixels or so of an edge (your main form's Location.Left + form width) or height (your main form's Location.Top + form height), then go ahead and set the .Left and .Top properties so that your application "docks" in the corners.
Edit: One other note - when you actually do the "snapping" you may also want to move the cursor position the relative distance to make it stay on the same point on the window bar. Otherwise your form may become a giant ping pong ball between the cursor position and your "snappy" functionality as the MouseMove and form location changed events fight against each other.
我不知道您是否找到了解决方案,但我为此创建了一个小组件:http://www.formsnapper。 net - 它跨越进程边界!
I don't know if you found your solution, but I created a small component for just that: http://www.formsnapper.net - it snaps accross the process boundaries!
https://github.com/stax76/staxrip
https://github.com/stax76/staxrip