See this Stack Overflow answer this Stack Overflow answer, where Cody Gray Cody Gray explains the syntax for the two ways of registering event handlers in vb.net:
The first involves the use of the Handles keyword, which you append to the end of the event handler method's definition. [...] The second involves the explicit use of the AddHandler statement, just like += in C#.
This means instead of statically declaring all the handled events with a Handles
keyword, you write code to add the handlers yourself:
Public Sub New()
InitializeComponents()
AddHandler mnuEnglish.Click, AdressOf mnuEnglish_Click
AddHandler mnuFrench.Click, AdressOf mnuEnglish_Click
'...
End Sub
Or even better, loop through the menu items in that menu object, and assing all Click
events the AdressOf mnuEnglish_Click
, so you won't have the opportunity to forget updating that piece of code when you add a new language / menu item in the designer:
Public Sub New()
InitializeComponents()
ForEach item As ToolStripMenuItem In mnu.DropDownItems.OfType(Of ToolStripMenuItem)()
AddHandler item.Click, AdressOf mnuEnglish_Click
Next
End Sub
See this Stack Overflow answer, where Cody Gray explains the syntax for the two ways of registering event handlers in vb.net:
The first involves the use of the Handles keyword, which you append to the end of the event handler method's definition. [...] The second involves the explicit use of the AddHandler statement, just like += in C#.
This means instead of statically declaring all the handled events with a Handles
keyword, you write code to add the handlers yourself:
Public Sub New()
InitializeComponents()
AddHandler mnuEnglish.Click, AdressOf mnuEnglish_Click
AddHandler mnuFrench.Click, AdressOf mnuEnglish_Click
'...
End Sub
Or even better, loop through the menu items in that menu object, and assing all Click
events the AdressOf mnuEnglish_Click
, so you won't have the opportunity to forget updating that piece of code when you add a new language / menu item in the designer:
Public Sub New()
InitializeComponents()
ForEach item As ToolStripMenuItem In mnu.DropDownItems.OfType(Of ToolStripMenuItem)()
AddHandler item.Click, AdressOf mnuEnglish_Click
Next
End Sub
See this Stack Overflow answer, where Cody Gray explains the syntax for the two ways of registering event handlers in vb.net:
The first involves the use of the Handles keyword, which you append to the end of the event handler method's definition. [...] The second involves the explicit use of the AddHandler statement, just like += in C#.
This means instead of statically declaring all the handled events with a Handles
keyword, you write code to add the handlers yourself:
Public Sub New()
InitializeComponents()
AddHandler mnuEnglish.Click, AdressOf mnuEnglish_Click
AddHandler mnuFrench.Click, AdressOf mnuEnglish_Click
'...
End Sub
Or even better, loop through the menu items in that menu object, and assing all Click
events the AdressOf mnuEnglish_Click
, so you won't have the opportunity to forget updating that piece of code when you add a new language / menu item in the designer:
Public Sub New()
InitializeComponents()
ForEach item As ToolStripMenuItem In mnu.DropDownItems.OfType(Of ToolStripMenuItem)()
AddHandler item.Click, AdressOf mnuEnglish_Click
Next
End Sub
See this Stack Overflow answer, where Cody Gray explains the syntax for the two ways of registering event handlers in vb.net:
The first involves the use of the Handles keyword, which you append to the end of the event handler method's definition. [...] The second involves the explicit use of the AddHandler statement, just like += in C#.
This means instead of statically declaring all the handled events with a Handles
keyword, you write code to add the handlers yourself:
Public Sub New()
InitializeComponents()
AddHandler mnuEnglish.Click, AdressOf mnuEnglish_Click
AddHandler mnuFrench.Click, AdressOf mnuEnglish_Click
'...
End Sub
Or even better, loop through the menu items in that menu object, and assing all Click
events the AdressOf mnuEnglish_Click
, so you won't have the opportunity to forget updating that piece of code when you add a new language / menu item in the designer:
Public Sub New()
InitializeComponents()
ForEach item As ToolStripMenuItem In mnu.DropDownItems.OfType(Of ToolStripMenuItem)()
AddHandler item.Click, AdressOf mnuEnglish_Click
Next
End Sub
I'm pretty sure you don't need to specify .OfType(Of ToolStripMenuItem)()
, since item
is already declared to be a ToolStripMenuItem
- I'm not a vb.net expert, but in equivalent vb6 code the loop's body would not run for members of mnu.DropDownItems
that aren't of that type.
See this Stack Overflow answer, where Cody Gray explains the syntax for the two ways of registering event handlers in vb.net:
The first involves the use of the Handles keyword, which you append to the end of the event handler method's definition. [...] The second involves the explicit use of the AddHandler statement, just like += in C#.
This means instead of statically declaring all the handled events with a Handles
keyword, you write code to add the handlers yourself:
Public Sub New()
InitializeComponents()
AddHandler mnuEnglish.Click, AdressOf mnuEnglish_Click
AddHandler mnuFrench.Click, AdressOf mnuEnglish_Click
'...
End Sub
Or even better, loop through the menu items in that menu object, and assing all Click
events the AdressOf mnuEnglish_Click
, so you won't have the opportunity to forget updating that piece of code when you add a new language / menu item in the designer:
Public Sub New()
InitializeComponents()
ForEach item As ToolStripMenuItem In mnu.DropDownItems
AddHandler item.Click, AdressOf mnuEnglish_Click
Next
End Sub
I'm pretty sure you don't need to specify .OfType(Of ToolStripMenuItem)()
, since item
is already declared to be a ToolStripMenuItem
- I'm not a vb.net expert, but in equivalent vb6 code the loop's body would not run for members of mnu.DropDownItems
that aren't of that type.
See this Stack Overflow answer, where Cody Gray explains the syntax for the two ways of registering event handlers in vb.net:
The first involves the use of the Handles keyword, which you append to the end of the event handler method's definition. [...] The second involves the explicit use of the AddHandler statement, just like += in C#.
This means instead of statically declaring all the handled events with a Handles
keyword, you write code to add the handlers yourself:
Public Sub New()
InitializeComponents()
AddHandler mnuEnglish.Click, AdressOf mnuEnglish_Click
AddHandler mnuFrench.Click, AdressOf mnuEnglish_Click
'...
End Sub
Or even better, loop through the menu items in that menu object, and assing all Click
events the AdressOf mnuEnglish_Click
, so you won't have the opportunity to forget updating that piece of code when you add a new language / menu item in the designer:
Public Sub New()
InitializeComponents()
ForEach item As ToolStripMenuItem In mnu.DropDownItems.OfType(Of ToolStripMenuItem)()
AddHandler item.Click, AdressOf mnuEnglish_Click
Next
End Sub
See this Stack Overflow answer, where Cody Gray explains the syntax for the two ways of registering event handlers in vb.net:
The first involves the use of the Handles keyword, which you append to the end of the event handler method's definition. [...] The second involves the explicit use of the AddHandler statement, just like += in C#.
This means instead of statically declaring all the handled events with a Handles
keyword, you write code to add the handlers yourself:
Public Sub New()
InitializeComponents()
AddHandler mnuEnglish.Click, AdressOf mnuEnglish_Click
AddHandler mnuFrench.Click, AdressOf mnuEnglish_Click
'...
End Sub
Or even better, loop through the menu items in that menu object, and assing all Click
events the AdressOf mnuEnglish_Click
, so you won't have the opportunity to forget updating that piece of code when you add a new language / menu item in the designer:
Public Sub New()
InitializeComponents()
ForEach item As ToolStripMenuItem In TheParentMenumnu.ItemsDropDownItems
AddHandler item.Click, AdressOf mnuEnglish_Click
Next
End Sub
I'm pretty sure you don't need to specify .OfType(Of ToolStripMenuItem)()
, since item
is already declared to be a ToolStripMenuItem
- I'm not a vb.net expert, but in equivalent vb6 code the loop's body would not run for members of mnu.DropDownItems
that aren't of that type.
See this Stack Overflow answer, where Cody Gray explains the syntax for the two ways of registering event handlers in vb.net:
The first involves the use of the Handles keyword, which you append to the end of the event handler method's definition. [...] The second involves the explicit use of the AddHandler statement, just like += in C#.
This means instead of statically declaring all the handled events with a Handles
keyword, you write code to add the handlers yourself:
Public Sub New()
InitializeComponents()
AddHandler mnuEnglish.Click, AdressOf mnuEnglish_Click
AddHandler mnuFrench.Click, AdressOf mnuEnglish_Click
'...
End Sub
Or even better, loop through the menu items in that menu object, and assing all Click
events the AdressOf mnuEnglish_Click
, so you won't have the opportunity to forget updating that piece of code when you add a new language / menu item in the designer:
Public Sub New()
InitializeComponents()
ForEach item As ToolStripMenuItem In TheParentMenu.Items
AddHandler item.Click, AdressOf mnuEnglish_Click
Next
End Sub
See this Stack Overflow answer, where Cody Gray explains the syntax for the two ways of registering event handlers in vb.net:
The first involves the use of the Handles keyword, which you append to the end of the event handler method's definition. [...] The second involves the explicit use of the AddHandler statement, just like += in C#.
This means instead of statically declaring all the handled events with a Handles
keyword, you write code to add the handlers yourself:
Public Sub New()
InitializeComponents()
AddHandler mnuEnglish.Click, AdressOf mnuEnglish_Click
AddHandler mnuFrench.Click, AdressOf mnuEnglish_Click
'...
End Sub
Or even better, loop through the menu items in that menu object, and assing all Click
events the AdressOf mnuEnglish_Click
, so you won't have the opportunity to forget updating that piece of code when you add a new language / menu item in the designer:
Public Sub New()
InitializeComponents()
ForEach item As ToolStripMenuItem In mnu.DropDownItems
AddHandler item.Click, AdressOf mnuEnglish_Click
Next
End Sub
I'm pretty sure you don't need to specify .OfType(Of ToolStripMenuItem)()
, since item
is already declared to be a ToolStripMenuItem
- I'm not a vb.net expert, but in equivalent vb6 code the loop's body would not run for members of mnu.DropDownItems
that aren't of that type.