在MyApplication_Startup中使用MouseEventArgs [英] using MouseEventArgs in MyApplication_Startup

查看:68
本文介绍了在MyApplication_Startup中使用MouseEventArgs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我在声明和使用MyApplication_Startup中的mouseEvents(例如mouseClick和mouseMove)时遇到问题.
我如何定义它们.
例如,我希望当应用程序启动时,如果用户单击鼠标,则会发生某些事情.
请帮助我
非常感谢

解决方案

不要这样做.

应用程序启动是您初始化一堆事情的地方-那就是应该在那里做的所有事情.

通常并没有很好地定义启动时会初始化什么顺序的东西-因此,如果您在那做任何事情都依赖于初始化的其他任何东西,它可能一次就会起作用,而下一次会失败.


另外,应用程序启动时单击鼠标"的概念也没有很好地定义.

什么时候是应用程序启动时"?

如果单击是代码执行之前的一毫秒,还是执行之后的一毫秒,会发生什么?

(此外,鼠标单击可能不是一个好的选择,因为Windows应用程序通常是通过鼠标单击启动的...)

充其量,您可能会在启动代码中读取键盘状态并设置一个标志,表明当时已按下或未按下某个键.然后,在您的应用程序完成初始化之后,检查该标志并执行您想做的任何事情.

或者,您可以在启动代码中读取系统时钟并将其保存在某处.然后,在正常的鼠标事件处理代码中(初始化完成后),检查是否在启动时间的一定时间内收到了鼠标事件. (即使那样也不可靠,因为您无法预测应用程序启动将花费多长时间,因为这取决于系统中正在发生的其他事情.)


hi i have problem in declaration and using mouseEvents such as mouseClick and mouseMove in MyApplication_Startup.
how can i define them.
for example i want that when the application stars, if the user clicks the mouse, something happens.
plz help me
thanks alot

解决方案

Don''t do that.

Application startup is where you initialize a bunch of things -- and that''s all that should be done there.

It''s generally not well defined what order things are intitialized at startup -- so if you do anything there that depends on anything else being initialized it might work one time and fail the next.


Also, the idea of "clicking the mouse when the application starts" is not well defined.

When exactly is "when the application starts"?

What happens if the click is a millisecond prior to your code executing, or a millisecond after??

(Plus, mouse clicks are probably a bad choice since windows applications are generally started by mouse clicks...)

At best you might read the keyboard state in your startup code and set a flag saying that some key is pressed or isn''t pressed at that time. Then after your application is initialization is complete, check that flag and do whatever you wanted to do.

Or you might read the system clock in your startup code and save it somewhere. Then in your normal mouse event handling code (after initialization is complete) check if you are receiving a mouse event within some amount of time of the start up time. (Even that is not reliable since you can''t predict how long your application will take to start since that''s dependent on what else is happening in the system.)


这篇关于在MyApplication_Startup中使用MouseEventArgs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆