Как я могу добавить события в динамически создаваемый PictureBox? (Visual Basi c) - PullRequest
0 голосов
/ 20 марта 2020

Как видите, это мой текущий код для создания коробок с картинками. По сути, я собираюсь сделать около ста из них, поэтому делать это вручную будет огромной болью. Хотя я не знаю, как добавлять события, как ты это делаешь?

1 Ответ

0 голосов
/ 21 марта 2020

Импортирует System.ComponentModel

Publi c Класс frmScreen Наследует форму Dim CellColor As PictureBox '' '

Private Sub Screen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    CellColor = New PictureBox
    With CellColor
        .BackColor = Color.Azure
        '
        '
        '
    End With

    'When you do click on the CellColor control the you go to ScreenPicBox method
    AddHandler CellColor.Click, AddressOf ScreenPicBox_Checked

    'If you need to remove by code the handler you can write the following instruction
    RemoveHandler CellColor.Click, AddressOf ScreenPicBox_Checked

End Sub

Private Sub ScreenPicBox_Checked(sender As Object, e As EventArgs)
    If TypeOf sender Is PictureBox Then
        'do anything here
    End If


End Sub

Конечный класс

Я надеюсь, что это показывает как хочешь, Дарп мо sh. Удачного кодирования! :)

...