我可以在Visual Studio中定制自动生成事件处理程序吗? [英] Can I customize automatic event handler generation in Visual Studio?

查看:158
本文介绍了我可以在Visual Studio中定制自动生成事件处理程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在代码中订阅事件时,Visual Studio会在 + = 之后自动完成代码,并生成相应的事件处理程序:

When you subscribe to an event in code, Visual Studio automatically completes the code after += and generates the appropriate event handler:

button.Click += new EventHandler(button_Click);
//              ↑_____auto generated code_____↑

注意它如何显式创建委托实例:甚至虽然方法组可以隐式转换为代理,因为C#2,IDE行为在VS2010中仍然没有改变。

Notice how it explicitly creates the delegate instance: even though method groups are implicitly convertible to delegates since C# 2, the IDE behavior still hasn't changed in VS2010.

所以我想知道,有没有办法要生成这样的代码?

So I'd like to know, is there a way to generate code like this instead?

button.Click += button_Click;






编辑

只是为了让所有人清楚:上面的代码是不是在设计器文件中(如果是这种情况,我不在乎使用哪种语法)。这是您在事件名称后键入 + = 时触发的片段,然后按 TAB


EDIT
just to make things clear to everyone: the code above is not in a designer file (I wouldn't care which syntax is used if it was the case). It's the snippet that is triggered when you type += after an event name and press TAB

EDIT2

我将此报告为建议在Connect 上,如果您还想要

EDIT2
I reported this as a suggestion on Connect, you can vote for it if you also want the current behavior to be changed

推荐答案

建议连接被标记为固定的,所以新的行为应该包含在VS11的下一个公开版本中。

The suggestion on Connect has been marked as fixed, so the new behavior should be included in the next public build of VS11.

编辑:刚刚检查,确实包含在测试版中。

just checked, it is indeed included in the beta.

这篇关于我可以在Visual Studio中定制自动生成事件处理程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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