Create an EventHandler in Visual Basic .NET

José Carlos 886 Reputation points
2023-06-20T22:23:31.92+00:00

Friends,

How do I create an EventHandler in Visual Basic .NET for a PictureBox set?

In C# is:

Thank you.

 foreach (Control control in groupBox2.Controls)             
{                 
control.Click += new EventHandler(PictureBox_Click);             
}                 

void PictureBox_Click(object sender, EventArgs e)         
{             
PictureBox SelectedPictureBox = (PictureBox)sender;              
switch (SelectedPictureBox.Name)             
{
xxxxxxx
}
Developer technologies VB
Developer technologies Visual Studio Other
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-06-21T01:31:18.3266667+00:00

    Hi @José Carlos ,

    Please check if the following code hepls.

        For Each control As Control In groupBox2.Controls
        AddHandler control.Click, AddressOf PictureBox_Click
    	Next
    
        Private Sub PictureBox_Click(sender As Object, e As EventArgs)
            Dim SelectedPictureBox As PictureBox = DirectCast(sender, PictureBox)
            Select Case SelectedPictureBox.Name
                Case "xxxxxxx"
    
                Case Else
    
            End Select
        End Sub
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.