处理 Windows Mobile Click 事件,使其不会“排队”当我的程序被阻塞时
我为 WinMo 6.x 编写了一个简单的应用程序来娱乐我的女儿。它保存一组动物图像与动物噪声对,并随机显示其中一个图像。单击图像时,会播放动物噪音,两岁的孩子会分心:-),然后显示下一张图像。
然而,由于她倾向于猛击屏幕,因此实际流程是图像显示后她点击了几次;播放几种动物的声音,然后图像变为下一个随机动物。
我的猜测是,操作系统正在对点击事件进行排队,而程序在播放噪音时会被阻塞,然后尽快处理它们。就像您可以在机器挂起时继续打字一样,并且当所有内容再次清除时显示文本。
因此,该表单有两个变量,
Private thisCollectionOfThings As ObjectStore
Private currentObject As RealWorldObject
ObjectStore 是 List(Of RealWorldObject) 的包装类,它具有 getNextObject 方法,该方法返回随机 RealWorldObject,并检查最近是否未返回特定对。
在我们的表单中...
Private Sub picBox_Click(ByVal sender As Object, ByVal e As EventArgs)
RemoveHandler picBox.Click, AddressOf picBox_Click
picBox.BackColor = Color.Gray
If currentObject.getSoundLocation() <> "" Then
currentObject.playSound()
refreshScreen()
End If
End Sub
Private Sub refreshScreen()
picBox.Image = Nothing
currentObject = thisCollectionOfThings.getNextObject()
If Not currentObject Is Nothing Then addImage()
AddHandler picBox.Click, AddressOf picBox_Click
End Sub
Private Sub addImage()
picBox.Image = New Bitmap(currentObject.getImageLocation())
End Sub
您可以看到我尝试删除事件处理程序来尝试避免点击排队问题,但它不起作用。
任何关于如何避免这种情况的建议都将非常感激...否则我会尝试在图片框控件周围编写自己的包装器来尝试处理点击,但如果其他人的经验表明我不愿意浪费我的时间那没有帮助。
I've written a simple application for WinMo 6.x to entertain my daughter. It holds a set of animal image to animal noise pairs and randomly displays one of the images. When the image is clicked the animal noise plays and the two year old is distracted :-) and then the next image is displayed.
However, since she tends to bash at the screen the actual flow is that the image displays and she clicks several times; several animal noises are played and then the image changes to the next random animal.
My guess is that the OS is queueing the click events while the program is blocking as it plays the noise and then processing them as soon as it can. In much the same way as you can carry on typing while your machine hangs and the text displays when everything clears again.
So the form has two variables
Private thisCollectionOfThings As ObjectStore
Private currentObject As RealWorldObject
ObjectStore is a wrapper class around a List(Of RealWorldObject) that has a getNextObject method that returns a random RealWorldObject having checked that particluar pair hasn't been returned recently.
In the form we have...
Private Sub picBox_Click(ByVal sender As Object, ByVal e As EventArgs)
RemoveHandler picBox.Click, AddressOf picBox_Click
picBox.BackColor = Color.Gray
If currentObject.getSoundLocation() <> "" Then
currentObject.playSound()
refreshScreen()
End If
End Sub
Private Sub refreshScreen()
picBox.Image = Nothing
currentObject = thisCollectionOfThings.getNextObject()
If Not currentObject Is Nothing Then addImage()
AddHandler picBox.Click, AddressOf picBox_Click
End Sub
Private Sub addImage()
picBox.Image = New Bitmap(currentObject.getImageLocation())
End Sub
You can see I've resorted to trying to remove the event handler to try and avoid the click queueing issue but it isn't working.
Any advice on how to avoid this would be super-appreciated... Otherwise I'll try writing my own wrapper around the picture box control to try and handle the click but I'm loathe to use up my time if someone else's experience suggests that wouldn't help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会为了简单起见(KISS):
I'd go for simplicity (KISS):