我試圖繪製一個PictureBox的數組,用於測試我爲每個picturebox使用相同的圖片。在vb.net中繪製一個PictureBox的數組
但不是顯示圖片,它顯示藍色。
我會告訴你一個圖片,但我沒有信譽10 ..
Dim teren(120) As PictureBox
Dim x_locatie As Integer = 1, y_locatie As Integer = 0
For i = 0 To 10
x_locatie = 210
For j = 0 To 12
teren(i * j) = New PictureBox()
teren(i * j).Size = New Size(61, 61)
teren(i * j).Name = "x" + i.ToString + "y" + j.ToString
teren(i * j).Location = New Point(x_locatie, y_locatie)
Dim locatie As String = folder + "\harta\test.png"
teren(i * j).ImageLocation = locatie
teren(i * j).Show()
Next
y_locatie += 61
Next
我也嘗試過其他方法,但結果相同。
Sub PictureBox1_Paint(sender1 As Object, er As PaintEventArgs)
If myImage IsNot Nothing Then
Dim r As New Rectangle(x, y, xlatime, ylungime)
er.Graphics.DrawImage(myImage, r)
End If
End Sub
Sub deseneaza(ByVal poza As String, ByRef x_perm As Integer, ByRef y_perm As Integer, ByRef lungime As Integer, ByRef latime As Integer)
myImage = Image.FromFile(poza)
x = x_perm
y = y_perm
xlatime = latime
ylungime = lungime
Refresh()
End Sub
'this part of code is in body of another function
Dim x_locatie As Integer = 1, y_locatie As Integer = 0
For i = 0 To 10
x_locatie = 210
For j = 0 To 12
Dim locatie As String = folder + "\harta\test.png"
deseneaza(locatie, x_locatie, y_locatie, 61, 61)
Next
y_locatie += 61
Next
我在其他線程,他們的問題的解決方案是類似的東西Dim teren() As PictureBox {teren1, teren2 , ... , teren n}
但在我的情況下,問題是,我需要120個PictureBoxes看見了,我認爲它必須是一個辦法做到這一點,而無需編寫120個pictureboxes 。
這似乎有點控制沉重。你可以使用一個List(矩形)列表,併爲它們繪製圖像。內存佔用更低。 – OneFineDay
@OneFineDay但我必須寫出120個矩形,對吧? –
儘可能多的你需要! – OneFineDay