views:

628

answers:

4

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?

+3  A: 

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

Matt Briggs
Any way to have that automated, instead of having to do it manually? i've done that before with web service classes and it really sucked.
hmcclungiii
Cut and paste from the designer.
recursive
+3  A: 

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.

Jorge Villuendas
Thanks for the exact implementation details.
hmcclungiii
A: 

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.

Frank V
+3  A: 

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.

Jon Limjap