以下Sub显示以下错误消息:
粗体1:"许多关于' Friend WithEvents的论据btnChoice As Button'"
粗体2:"许多关于&Frieff WithEvents的参数imgPicture As Button'"
粗体3:"' Friend WithEvents btnChoice As Button'没有参数,其返回类型无法编入索引"
大胆4-8:"'朋友WithEvents imgPicture作为PictureBox'没有参数,其返回类型无法编入索引"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim intNextNumber As Integer
For intNextNumber = 1 To 8
btnChoice(**intNextNumber**)
imgPicture(**intNextNumber**)
Next
Call MoveControls(btnChoice)
Call MoveControls(imgPicture)
For intNextNumber = 1 To 8
**btnChoice**(intNextNumber).Visible = True
Next
Randomize()
Dim aintRandomNumber(0 To 8) As Integer
Call GetRandomNumbers(aintRandomNumber)
For intNextNumber = 1 To 8
Select Case aintRandomNumber(intNextNumber)
Case 1, 2
**imgPicture**(intNextNumber).Picture = Image.FromFile("C:\Users\Jonas Bakari Reitan\Desktop\Bilde1.jpg")
**imgPicture**(intNextNumber).Tag = "Sirkel"
Case 3, 4
**imgPicture**(intNextNumber).Picture = Image.FromFile("C:\Users\Jonas Bakari Reitan\Desktop\Bilde2.jpg")
**imgPicture**(intNextNumber).Tag = "Firkant"
Case 5, 6
**imgPicture**(intNextNumber).Picture = Image.FromFile("C:\Users\Jonas Bakari Reitan\Desktop\Bilde3.jpg")
**imgPicture**(intNextNumber).Tag = "Diamant"
Case 7, 8
**imgPicture**(intNextNumber).Picture = Image.FromFile("C:\Users\Jonas Bakari Reitan\Desktop\Bilde4.jpg")
**imgPicture**(intNextNumber).Tag = "Pil"
End Select
Next
End Sub
答案 0 :(得分:0)
假设您的控件名为imgPicture1
到imgPicture8
,您可以使用Controls.Find
方法按名称访问它们。
Dim img = Me.Controls.Find("imgPicture" & index, True)