简体   繁体   English

Windows窗体中的窗体移动事件

[英]Form move events in Windows Forms

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. 我的问题如下:我在应用程序中有一个状态机,只要用户在屏幕上移动表单,我就需要能够暂停当前状态的ProcessInput函数。

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. 我在执行此操作的状态上有一个名为“ Paused”的属性,并且我覆盖了表单的OnMove事件,以便在事件触发时将该属性设置为true。

How do I resume the ProcessInput function of the state when the user is no longer moving the form? 当用户不再移动表单时,如何恢复状态的ProcessInput函数? (To be more specific, i am looking for an event to put a "state.Paused = false" in it) (更具体地说,我正在寻找一个将“ state.Paused = false”放入其中的事件)

Thx in advance for your help! Thx提前为您提供帮助!

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. 一旦计时器实际触发(在设置的持续时间内未重置),则设置state.Paused = false。

May be a bit rudimentry, but it should work... 可能有点初级,但是应该可以...

You need WM_MOVE message, it is send when the move is done. 您需要WM_MOVE消息,移动完成后将发送该消息。 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. 我不记得WinForms中是否有处理程序(事件),但是在最坏的情况下,您可以覆盖window的WndProc并手动处理消息-采用“老式” C样式。

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

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