1

我想为我单击的图片框设置一个新图像。所以我认为我可以在同一个 clickevent(SelectEvent6x6) 上发送所有内容,然后使用 sender.name 来识别希望图片框需要更改。然而这不起作用,因为它是一个字符串而不是一个对象

    Private Sub SelectEvent6x6(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles PB00.Click, PB55.Click, PB54.Click, PB53.Click, PB52.Click, PB51.Click, PB50.Click, PB45.Click, PB44.Click, PB43.Click, PB42.Click, PB41.Click, PB40.Click, PB35.Click, PB34.Click, PB33.Click, PB32.Click, PB31.Click, PB30.Click, PB25.Click, PB24.Click, PB23.Click, PB22.Click, PB21.Click, PB20.Click, PB15.Click, PB14.Click, PB13.Click, PB12.Click, PB11.Click, PB10.Click, PB05.Click, PB04.Click, PB03.Click, PB02.Click, PB01.Click
        Dim Selected As String
        Selected = sender.name
        'PB00.Image = Image.FromFile(My.Computer.FileSystem.CurrentDirectory + "\objects20130308b\map\mapgrassselected.png")
        Selected.Image = Image.FromFile(My.Computer.FileSystem.CurrentDirectory + "\objects20130308b\map\mapgrassselected.png")
4

2 回答 2

2

我认为,发件人应该是图片框本身。

于 2013-03-08T12:25:35.123 回答
1

做这个:

Dim picBox as PictureBox = CType(sender, PictureBox)
picBox.Image = Image.FromFile(imagePath)
于 2013-03-08T12:38:30.250 回答