单击Windows激活控件 [英] Click control on windows activation

查看:100
本文介绍了单击Windows激活控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个Windows窗体应用程序。当我单击一个窗口时,这会激活表单,然后我需要再次单击以调用特定的控件单击事件。例如,如果我点击一个按钮,这会激活表格,然后我需要再次点击按钮。



有没有办法执行控制点击和窗口激活一键点击?我希望这适用于任何可点击的控件(菜单,按钮,标签等)



谢谢

Hi,

I have a windows forms application. When I click on a window this activates the form and then I need to click again to call the particular control click event. For example if I click on a button this activates the form and then I need to click the button again.

Is there a way to perform the control click and window activation in one click? Preferably I would want this to work with whatever the clickable control is (menu,button, label etc)

Thanks

推荐答案

是的,有这样的方法,但你永远不应该为常规UI开发。这是一种完全滥用,使您的代码不可靠,不利于支持。这只是表明你不知道如何合法地开发UI,没有别的。



所有你需要的是学习一些UI开发。



在你的特定情况下,你有足够的,没有点击模拟:你有事件 System.Windows.Forms.Control.Click 一个按钮,以及事件 System.Windows.Form.Activated ,或者,无论如何,当您编写表单类时,您可以简单地覆盖虚拟表单方法 System.Windows.Forms.Form.OnActivated



在你的问题中,你永远不会解释你为什么会这样做喜欢对激活做一些动作,以及为什么这样的动作应该与按钮点击相同。我怀疑你真的需要它,但在这里,你已经拥有了你需要的一切。为此,您只需要能够...编写代码,特别是方法(而不是仅填写设计者创建的代码)。



只需创建一些表单实例方法做你需要的。从按钮单击事件和激活事件中调用此方法。有了主意吗?



-SA
Yes, there are such ways, but you never should do it for "regular" UI development. This is a total abuse which makes your code unreliable and bad for support. This is only the indication that you have no idea how to develop UI legitimately, nothing else.

All you need is to learn some UI development.

In your particular case, you have more then enough, without click simulation: you have the event System.Windows.Forms.Control.Click of a button, and the event System.Windows.Form.Activated, or, alternatively, as you are writing you form class anyway, you can simply override the virtual form method System.Windows.Forms.Form.OnActivated.

In your question, you never explain why would you like to do some action on activation, and why such action should be the same as on the button click. I doubt you really need exactly that, but here, you also already have everything you need. For this, you only need to be able to… write code, in particular, method (instead of just filling in those created by the designer).

Just create some form instance method doing what you need. Call this method from the button click event and from the activation event. Got the idea?

—SA


这篇关于单击Windows激活控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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