У меня есть массив PictureBox, который создает сетку картинок 10,10, как я могу пометить один из этих ящиков с картинками?
Public Class Form1
Inherits System.Windows.Forms.Form
Dim active As Boolean = True
Dim images(8) As Image 'declares image array
Dim zonesY As Integer = 10
Dim zonesX As Integer = 100
Dim Guy As Object
Dim generator As New Random
' Dim x As Integer 'declares x as an integer variable
' Dim y As Integer 'declares y as an integer variable
Dim oGrid(zonesX, zonesY) As PictureBox
Private Sub SetupGrid()
images(0) = Image.FromFile("clear.png")
images(1) = Image.FromFile("1.png")
images(2) = Image.FromFile("2.png")
images(3) = Image.FromFile("3.png")
images(4) = Image.FromFile("4.png")
images(5) = Image.FromFile("5.png")
images(6) = Image.FromFile("blank.png")
images(7) = Image.FromFile("hit.png")
images(8) = Image.FromFile("mine.png")
For y As Integer = 1 To zonesY 'starts a For loop (1 to zonesY number of loops)
For x As Integer = 1 To zonesX 'starts a For loop (1 to zonesX number of loops)
Dim zonesize1 As Integer
Dim zonesize2 As Integer
Dim blockStatus As Integer
Dim allZones As Integer
allZones = zonesX * zonesY
blockStatus = generator.Next(0, allZones)
oGrid(x, y).Name = x & ", " & y
MsgBox(oGrid(x, y).Name)
If blockStatus < (allZones / 5) Then
oGrid(x, y).Tag = True
If oGrid(x, y).Tag = True Then
oGrid(x, y).Image = images(8)
End If
Else
oGrid(x, y).Tag = False
If oGrid(x, y).Tag = False Then
oGrid(x, y).Image = images(6)
End If
End If
oGrid(x, y).Height = 16
oGrid(x, y).Width = 16
zonesize1 = oGrid(x, y).Height 'sets out all of the boxes on the form.
zonesize2 = oGrid(x, y).Width
oGrid(x, y).Left = ((x - 1) * zonesize1 + 15)
oGrid(x, y).Top = ((y - 1) * zonesize2 + 15)
Me.Controls.Add(oGrid(x, y))
' Wire this control up to an appropriate event handler
AddHandler oGrid(x, y).Click, AddressOf pbxNewZoneClicked
Next
Next
Me.Height = 500 'sets the height of fmmGame
Me.Width = 500 'sets the width of frmGame
End Sub
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetupGrid()
End Sub
Private Sub CheckHits()
Dim FicX1 As Integer = zonesX - 1
Dim FicY1 As Integer = zonesY - 1
Dim counter As Integer = 0
End Sub
Private Sub pbxNewZoneClicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
If active = True Then
Dim pb As PictureBox = DirectCast(sender, PictureBox)
Dim splitName() As String = pb.Name.Split(",")
Dim x As Integer = Convert.ToInt32(splitName(0))
Dim y As Integer = Convert.ToInt32(splitName(1))
Dim Status As String = "Clear" ' Status - Testing Purposes Only
If pb.Tag = True Then ' Status - Testing Purposes Only
Status = "Mine" ' Status - Testing Purposes Only
End If
' MsgBox(pb.Name & vbCrLf & "Status: " & Status, , "Test") ' Post Statistics of box.
Dim counter As Integer = 0
If oGrid(x, y).Tag = True Then
pb.Image = images(7) ' Hit Image
active = False
' MsgBox("No Longer Active", , "Test") ' Testing Purposes Only
ElseIf oGrid(x, y).Tag = False Then
pb.Image = images(counter) ' Clear Image by default.
End If
End If
End Sub
End Class
Я пытаюсь проверить, если изображение вверху, один и оставилтег = True = + = 1 счетчик.