-
February 12th, 2009, 04:20 AM
#1
vb.net handles vs addhandler
I am aware that I'm posting vb specific keywords in a c# forum, and I am confident that the experts here do not have an issue with this. I am a preferred c# developer, that is to say, I prefer c# (I wont get into my reasons, thats another topic). With that said.
Tell me what you think about using the handles keyword at design time as opposed to wiring up the events with addhandler.
I am asking this question to c# developers, because those in the know, know why I ask c# developers.
Please do tell, I'm interested to hear your thoughts.
(yes I understand that the handles get converted to addhandler during compile)
-
February 12th, 2009, 07:27 AM
#2
Re: vb.net handles vs addhandler
Originally Posted by Traps
Tell me what you think about using the handles keyword at design time as opposed to wiring up the events with addhandler.
If Visual Designer takes care of it, I do not care.
If I need to add it, I prefer AddHandler since it makes my intention more clear (Handles is usually hidden far right). I find it also easier to work with if I need to translate code between C# and VB.NET.
-
February 12th, 2009, 08:20 PM
#3
Re: vb.net handles vs addhandler
'Handles' has more complex behind-the-scenes behavior.
With 'Handles' (and the corresponding object declared 'WithEvents'), you can assign to the WithEvents variable and the events wired via 'Handles' are not lost.
e.g., the following VB code
Code:
Private WithEvents x As DelegateServer
Private Sub z1(ByVal member As MemberNode) Handles x.DoubleClick
End Sub
strictly translates the following C#:
Code:
[System.Runtime.CompilerServices.AccessedThroughProperty("x")]
private DelegateServer _x;
private DelegateServer x
{
[System.Diagnostics.DebuggerNonUserCode]
get
{
return this._x;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized), System.Diagnostics.DebuggerNonUserCode]
set
{
if (this._x != null)
{
this._x.DoubleClick -= z1;
}
this._x = value;
if (this._x != null)
{
this._x.DoubleClick += z1;
}
}
}
private void z1(MemberNode member)
{
}
but of course the more usual conversion is the not-quite-equivalent:
Code:
private DelegateServer x;
//INSTANT C# TODO TASK: Insert the following converted event handler wireups at the end of the 'InitializeComponent' method for forms, 'Page_Init' for web pages, or into a constructor for other classes:
x.DoubleClick += new System.EventHandler(z1);
private void z1(MemberNode member)
{
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|