Visual Studio 与 #Develop - 默认事件处理程序
Visual Studio 和 SharpDevelop 并不都设置委托以相同的方式处理事件。 它们的设置方式略有不同。 这使得在一个地方使用 VS 而在另一个地方(在同一个项目上)使用 #Develop 变得很困难。
例如,在 VB 中,Visual Studio 执行以下操作:
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
并且...
Friend WithEvents OK_Button As System.Windows.Forms.Button
以便声明控件,不仅使用不同的范围(这也可能是一个问题,但不是本文的主题),而且使用 withevents。 然后通过handles 子句将事件处理程序分配给它。
在#Develop中,它是这样完成的...
Sub OK_ButtonClick(sender As Object, e As EventArgs)
End Sub
然后
Private button1 As System.Windows.Forms.Button
,在InitializeComponent方法中
AddHandler Me.button1.Click, AddressOf Me.OK_ButtonClick
最烦人的事情是,即使以一种方式完成,另一种ide也会重做它,有重复的声明,并且当然,编译时错误。
有谁知道解决这个问题的方法,某种自定义默认处理程序的方法? 即使只是通过某种方式将其关闭,这样就可以手动输入?
Visual Studio and SharpDevelop do not both set up delegates to handle events in the same way. The way they are set up is a little bit different. This makes it difficult to use VS in one place and #Develop in another (on the same project).
For Example, in VB, Visual Studio does the following:
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
And ...
Friend WithEvents OK_Button As System.Windows.Forms.Button
So that the control is declared, not only with a different scope (this can be a problem also, but not the topic of this post) but with a withevents. The event handler is then assigned to it by a handles clause.
in #Develop, it is done like this ...
Sub OK_ButtonClick(sender As Object, e As EventArgs)
End Sub
and ...
Private button1 As System.Windows.Forms.Button
Then, in the InitializeComponent method
AddHandler Me.button1.Click, AddressOf Me.OK_ButtonClick
The most annoying thing about this, is even if it is done one way, the other ide will redo it, having duplicate declarations, and of course, compile time errors.
Does anyone know of a way around this, some way to customize the default handlers? even if it is just some way that they can be turned off, so it can just be typed manually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Sharpdevelop 是在 LGPL 许可下发布的,因此您始终可以获取源代码并进行任何您想要的更改。
对于您想要的更改,您可能需要更改或重写 VBNetDesignerGenerator 类中的 InsertComponentEvent 和 CreateEventHandler 方法。 它位于 FormsDesigner 项目中。
您可以在此处获取源代码。
Sharpdevelop is released under a LGPL license, so you can always get the source and make any changes you want.
For the changes you want, you may need to change or override the InsertComponentEvent and CreateEventHandler methods in the VBNetDesignerGenerator class. It's in the FormsDesigner project.
You can get the source here.
将它们从 .designer 中取出,并在后面的代码的构造函数中手动将它们连接起来。 .designer 由您使用的任何工具的设计者重新生成
take them out of the .designer and wire them up manually in the constructor in the code behind. the .designer is regenerated by the designer of whatever tool you use
虽然我通常不会同意那些说“这个项目是开源的,自己修改代码库”的人,但在这种情况下,这可能是一个有效的答案。
#develop 之所以这样做,是因为它是 C# 如何添加事件处理程序的直接移植,例如,
仅仅是以下内容的直接翻译:
如果您使用 C#,Visual Studio 和 #Develop 都会处理代码中的事件创建方式完全相同。
显然,没有人关注 #Develop 中常见的 Visual Basic 用例,正如我上面所说,这是一种边缘情况,您可能需要自己调整代码,甚至可能回馈 #Develop 源代码对于这个特殊情况。
我确信使用 #Develop for Visual Basic 的其他人都会对此表示赞赏。
While I'm not one who would usually agree with people who say that "this project is open source, modify the codebase yourself", this is one case where it might be a valid answer.
The reason why #develop is doing things the way it is doing it is because it's a direct port of how C# adds event handlers, e.g.,
is merely a direct translation of:
If you were using C#, both Visual Studio and #Develop will handle event creation in code precisely the same way.
Obviously, no one is attending to the common Visual Basic usecase in #Develop, and as I said above, this is one of those fringe cases wherein you just might have to tweak the code yourself, or maybe even contribute back to the #Develop source for this particular case.
I'm sure everyone else who uses #Develop for Visual Basic would appreciate that.
这不是最实用的建议,但我保证它会为您完成工作。
#Develop 是开源的。 因此,理论上您可以将代码库修改为与 Visual Studio.net 相同的行为...我不确定这可能涉及多少,但我想我会分享我的想法...
作为进行更改的替代方案您自己,您可以联系核心团队将此作为功能请求。 也许捐款会有所帮助...其他人可能也对这一变化感兴趣。
问候,
弗兰克·V.
This isn't going to be the most practical suggestion, but I promise that it'd get the job done for you.
#Develop is open source. So, theoretically you could modify the code base to the same behavior as Visual Studio.net... I'm not sure how involved this might be but I thought I'd share my idea...
As an alternative to making the change your self, you might contact the core team about this as a feature request. Perhaps a donation would help... Others might also be interested in this change.
Regards,
Frank V.