如何向动态创建的 PictureBox 添加事件? (视觉基础)
How can I add events to a dynamically created PictureBox? (Visual Basic)
如您所见,这是我目前制作图片框的代码。基本上,我要制作大约一百个,所以手工制作会非常痛苦。我不知道如何添加事件,你是怎么做到的?
进口System.ComponentModel
Public Class frmScreen
继承形式
将 CellColor 调暗为 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
结束Class
我希望它能如您所愿,Darp mosh。编码愉快! :)
如您所见,这是我目前制作图片框的代码。基本上,我要制作大约一百个,所以手工制作会非常痛苦。我不知道如何添加事件,你是怎么做到的?
进口System.ComponentModel
Public Class frmScreen 继承形式 将 CellColor 调暗为 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
结束Class
我希望它能如您所愿,Darp mosh。编码愉快! :)