WinForms窗口拖动事件
WinForms 中是否有拖动窗口时触发的事件?
或者是否有更好的方法来做我想要的事情:当窗口被拖动时将窗口不透明度降低到 80%?
不幸的是,这很难搜索,因为每个人都在寻找从 shell 或其他对象中拖放的内容。
Is there an event in WinForms that get's fired when a window is dragged?
Or is there a better way of doing what I want: to drop the window opacity to 80% when the window is being dragged around?
Unfortunately this is stupidly tricky to search for because everyone is looking for drag and drop from the shell, or some other object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需 WndProc 黑客攻击,这可以正常工作:
移动还会触发 OnResizeXxx 事件。
No need for WndProc hacking, this works fine:
Moves also trigger the OnResizeXxx events.
这是
LocationChanged
你想要的事件:你必须重写
WndProc
并处理退出移动事件以将不透明度重置回1:不要忘记定义消息代码:
这可能会更有效处理
WM_ENTERSIZEMOVE
(代码0x0231
)消息而不是LocationChanged
,因为这只会导致设置不透明度一次(在拖动开始时),而不是在整个拖动过程中连续设置。It's the
LocationChanged
event you want:You'll have to override
WndProc
and handle the exit move event to reset the opacity back to 1:Not forgetting to define the message code:
It might be more efficient to handle the
WM_ENTERSIZEMOVE
(code0x0231
) message instead ofLocationChanged
as this would only result in setting the opacity once (at the start of the drag) rather than continually throughout the drag.