views:

51

answers:

2

Several times while debugging a VB.Net program I have found that continuation lines are missing from a subroutine designed to handle an event. The continuation character "_" is there but the following line is missing

Example:

Friend Sub TV_Main_Network_MouseDown _
    Handles TV_Main_Network.MouseDown

Will become

Friend Sub TV_Main_Network_MouseDown _

The first few times I figured I had made some editing error, but this has happened 3 times now, always in the same way (different subroutines but same place). As far as I can tell, no other continuation lines have changed.

Is this a bug or some feature I have missed?

+2  A: 

This happens if you delete a control that the handler is based on. For example, if you have a handler for button1 and delete button1 from the form (in design mode), the "handles" part of the sub statement is automatically deleted.

This also happens when you write a handler for a control that does not exist, then add the control to the form in design mode, and then double click on that control. In this case, it adds a new handler and removes the "handles..." from the previous handler.

xpda
Really? It works the opposite way in C#, where the handler remains, but now you get a compile error because the handler is referencing something that no longer exists. As aggravating as that sounds, I think I like it better than the VB way.
Robert Harvey
@Robert Harvey: That's not surprising; VB's editor on the whole is smarter than C#'s editor. Also, C# declares its event handlers in a separate file (the form's designer file) rather than declaring them in the code behind file like VB.NET does.
R. Bemrose
Would renaming a control delete the "handles...". I renamed several controls.
NormD
There's an option for that. By default, VB goes through the entire projects and renames references to the control you just renamed. That is REALLY handy. You can even rename the file in Solution Explorer and it will rename everything for you. I'm not sure what happens if this option is disabled.
xpda
+1  A: 

I have run into the same issue and xpda is right on the cause. I don't have enough reputation to mark the answer as helpful, so hopefully someone else will do it for me.

Wade73