Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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 :

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 :

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 :

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
deleted 267 characters in body
Source Link
Mathieu Guindon
  • 75.5k
  • 18
  • 194
  • 467

See this Stack Overflow answer, where Cody Gray explains the syntax for the two ways of registering event handlers in :

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 expert, but in equivalent 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 :

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 expert, but in equivalent 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 :

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
added 298 characters in body
Source Link
Mathieu Guindon
  • 75.5k
  • 18
  • 194
  • 467

See this Stack Overflow answer, where Cody Gray explains the syntax for the two ways of registering event handlers in :

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 expert, but in equivalent 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 :

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 :

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 expert, but in equivalent code the loop's body would not run for members of mnu.DropDownItems that aren't of that type.

Source Link
Mathieu Guindon
  • 75.5k
  • 18
  • 194
  • 467
Loading
lang-vb

AltStyle によって変換されたページ (->オリジナル) /