Windows 窗体中的窗体移动事件
我的问题如下:我在应用程序内有一个状态机,只要用户沿着屏幕移动表单,我就需要能够暂停当前状态的 ProcessInput 函数。
我在状态上有一个名为“Paused”的属性,它可以执行此操作,并且我重写表单的 OnMove 事件,以便在事件触发时将该属性设置为 true。
当用户不再移动表单时,如何恢复该状态的ProcessInput功能? (更具体地说,我正在寻找一个事件来放置“state.Paused = false”)
提前感谢您的帮助!
My problem is the following: i have a state machine inside an app and i need to be able to pause the current states's ProcessInput function as long as the user moves the form along the screen.
I have a property called "Paused" on the state which does that and i override the OnMove event of the form so that the property is set to true when the event fires.
How do I resume the ProcessInput function of the state when the user is no longer moving the form? (To be more specific, i am looking for an event to put a "state.Paused = false" in it)
Thx in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定是否有可以监听的特定事件,但是使用某种基于计时器的解决方法怎么样?
创建一个计时器,每次发生移动事件时重置并启用计时器。一旦计时器实际触发(在其设置的持续时间内未重置),则设置 state.Paused = false。
可能有点初级,但应该有用......
Not sure if there's a specific event you can listen for, but how about using some sort of timer based workaround?
Create a timer, reset and enable the timer every time a move event occurs. Once the timer actually fires (hasn't been reset for the duration it's set to), then set state.Paused = false.
May be a bit rudimentry, but it should work...
您需要 WM_MOVE 消息,它在以下时间发送移动完成。我不记得 WinForms 中是否有一个处理程序(事件),但在最坏的情况下,您可以覆盖窗口的 WndProc 并手动处理消息 - 以“老派”C 风格。
You need WM_MOVE message, it is send when the move is done. I don't remember whether there is a handler (an event) in WinForms for it, but in worst case you can override window's WndProc and process the message manually - in "old school" C style.