Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6714207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:28:06+00:00 2026-05-26T08:28:06+00:00

So basically, i have successfully randomized certain pictureboxes in a grid to contain mines,

  • 0

So basically, i have successfully randomized certain pictureboxes in a grid to contain mines, and show that mine, and for testing purposes, those mines are currently showing. What do you think I need to do to be able to say:

If, you click this box and mine = 1 (there’s a mine), then you lose.
Else, keep going.

simple enough, but i want to apply this to all boxes, no matter how big the grid is. (ZonesX * Zones Y)

The furthest I have gotten is being about to pop up a MsgBox() when anyone of them is clicked.

This is all created on runtime. Heres my code.

Public Class Form1
Inherits System.Windows.Forms.Form

Dim images(8) As Image 'declares image array

Dim zonesY As Integer = 10
Dim zonesX As Integer = 10

Dim Guy As Object
Dim pbxNewZone As PictureBox = DirectCast(Guy, PictureBox)  'declares pbxNewZone as a picturebox variable

Dim generator As New Random

Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    images(0) = Image.FromFile("blank.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("clear.png")
    images(7) = Image.FromFile("hit.png")
    images(8) = Image.FromFile("mine.png")

    Dim x As Integer  'declares x as an integer variable
    Dim y As Integer  'declares y as an integer variable
    Me.SuspendLayout()  'suspends creation of layout

    For y = 1 To zonesY 'starts a For loop (1 to zonesY number of loops)
        For x = 1 To zonesX  'starts a For loop (1 to zonesX number of loops)
            Dim zonesize1 As Integer
            Dim zonesize2 As Integer

            pbxNewZone = New PictureBox

            Dim blockStatus As Integer
            Dim allZones As Integer
            allZones = zonesX * zonesY
            blockStatus = generator.Next(0, allZones)

            pbxNewZone.Name = y & ", " & x
            If blockStatus < (allZones / 10) Then
                pbxNewZone.Tag = True
                If pbxNewZone.Tag = True Then
                    pbxNewZone.Image = images(8)
                End If
            Else
                pbxNewZone.Tag = False
                If pbxNewZone.Tag = False Then
                    pbxNewZone.Image = images(0)
                End If
            End If
            pbxNewZone.Height = 16
            pbxNewZone.Width = 16
            pbxNewZone.Tag = 0
            zonesize1 = pbxNewZone.Height 'sets out all of the boxes on the form.
            zonesize2 = pbxNewZone.Width
            pbxNewZone.Left = ((x - 1) * zonesize1 + 15)
            pbxNewZone.Top = ((y - 1) * zonesize2 + 15)
            Me.Controls.Add(pbxNewZone)
            '  Wire this control up to an appropriate event handler
            AddHandler pbxNewZone.Click, AddressOf pbxNewZoneClicked

        Next
    Next
    Me.Height = (pbxNewZone.Height * zonesY + 63)  'sets the height of fmmGame
    Me.Width = (pbxNewZone.Width * zonesX + 40)  'sets the width of frmGame

End Sub

Private Sub pbxNewZoneClicked(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Dim pb As PictureBox = DirectCast(sender, PictureBox)
    Dim pbTag As Boolean = DirectCast(sender, Boolean)

        If pb.Tag = True Then
            pb.Image = images(7) 'Hit Image
        Else
            pb.Image = images(6) 'Clear Image
        End If

    MsgBox(pb.Tag)

End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:28:06+00:00Added an answer on May 26, 2026 at 8:28 am

    A quick way to do it would be to use the Tag element of the PictureBox to keep track of whether there is a mine or not (or any of your other conditions).

    pbxnewzone.Tag = 1   'can assign tags to all of your pictureboxes in a loop or at random if need be
    

    Then, access the Tag property by casting the sender argument of your pbxNewZoneClicked method back to a PictureBox:

    Dim pb As PictureBox = DirectCast(sender, PictureBox)
    If (pb.Tag = 1) Then
        'change game accordingly
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically have 7 select statements that I need to have the results output
I have successfully created an email that sends on creation of a Kase, but
I have an Adorner in XAML that I'm using for ErrorValidation. Basically I have
I have successfully created a asp mvc app which basically has interface, service and
i have been successfully working with linq2sql and the linq DTOs (the classes that
I have written a Silverlight application that is basically an account registration form. I
Following this post and the other posts that it links to, I have successfully
I have successfully written a vhdl code to read and write a file. Basically
I basically have a page which shows a processing screen which has been flushed
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.