Mat*_*cer 4 vb.net onclick picturebox
我有一个flowLayoutPanel,我以编程方式添加新的panelLayouts.每个panelLayout都有一个pictureBox.这一切都运行良好,但我需要检测何时单击该图片框.如何在图片中添加活动?我似乎只能找到c#例子....
我添加图片的代码如下......
' add pic to the little panel container
Dim pic As New PictureBox()
pic.Size = New Size(cover_width, cover_height)
pic.Location = New Point(10, 0)
pic.Image = Image.FromFile("c:/test.jpg")
panel.Controls.Add(pic)
'add pic and other labels (hidden in this example) to the big panel flow
albumFlow.Controls.Add(panel)
Run Code Online (Sandbox Code Playgroud)
所以我假设在创建图像的某个地方我添加了一个onclick事件.如果可能的话,我还需要获取它的索引!谢谢你的帮助!
使用AddHandler语句订阅Click事件:
AddHandler pic.Click, AddressOf pic_Click
Run Code Online (Sandbox Code Playgroud)
pic_Click()方法的sender参数为您提供了对图片框的引用:
Private Sub pic_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim pic As PictureBox = DirectCast(sender, PictureBox)
' etc...
End Sub
Run Code Online (Sandbox Code Playgroud)
如果您需要有关特定控件的其他信息(如索引),则可以使用Tag属性.