Visual Studio 与 #Develop - 默认事件处理程序

发布于 2024-07-13 17:39:46 字数 1017 浏览 10 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烂人 2024-07-20 17:39:46

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.

水水月牙 2024-07-20 17:39:46

将它们从 .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

芯好空 2024-07-20 17:39:46

虽然我通常不会同意那些说“这个项目是开源的,自己修改代码库”的人,但在这种情况下,这可能是一个有效的答案。

#develop 之所以这样做,是因为它是 C# 如何添加事件处理程序的直接移植,例如,

AddHandler Me.button1.Click, AddressOf Me.OK_ButtonClick

仅仅是以下内容的直接翻译:

this.button1.Click += new EventHandler(OK_ButtonClick);

如果您使用 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.,

AddHandler Me.button1.Click, AddressOf Me.OK_ButtonClick

is merely a direct translation of:

this.button1.Click += new EventHandler(OK_ButtonClick);

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.

指尖微凉心微凉 2024-07-20 17:39:46

这不是最实用的建议,但我保证它会为您完成工作。

#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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文