Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio vs. #Develop - Default event handlers

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?

like image 951
hmcclungiii Avatar asked Dec 13 '22 05:12

hmcclungiii


2 Answers

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.

like image 177
Jorge Villuendas Zapatero Avatar answered Jan 05 '23 23:01

Jorge Villuendas Zapatero


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

like image 31
Matt Briggs Avatar answered Jan 05 '23 23:01

Matt Briggs