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

  • Home
  • SEARCH
  • 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 6686751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:12:30+00:00 2026-05-26T05:12:30+00:00

So basically, i have 2 int variables, x and y i am using to

  • 0

So basically, i have 2 int variables, x and y i am using to create a grid of pictureboxes.

This is all fluid and built on runtime.

I am trying to specifically change the picturebox on click if mine = 2.

I cannot specifically change one, when i click any, it changes all of them.

HELP PLEASE!!

Heres my code:

  Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim images(8) As Image 'declares image array

    Dim zonesY As Integer = 50
    Dim zonesX As Integer = 50

    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
                Dim mine As Integer

                pbxNewZone = New PictureBox

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

                pbxNewZone.Name = (zonesX * (y - 1)) + x
                If blockStatus < (allZones / 10) Then
                    mine = 1
                    If mine = 1 Then
                        pbxNewZone.Image = images(8)
                    End If
                Else
                    mine = 2
                    If mine = 2 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

        checkBlank()

    End Sub

    Public Sub checkBlank()

    End Sub

    Private Sub pbxNewZoneClicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ReDim x
        Do While y = 1 'starts a For loop (1 to zonesY number of loops)
            Do While x = 1  'starts a For loop (1 to zonesX number of loops)
                MsgBox("you have clicked " & x & ", " & y)
            Loop
        Loop
    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-26T05:12:30+00:00Added an answer on May 26, 2026 at 5:12 am

    In a Click event, sender will be the clicked object so…

    Dim pbx as PictureBox = DirectCast(sender,PictureBox)
    

    …will give you a reference (as pbx) to the clicked PictureBox – then you can do what you need to do with it.

    For ease, you may want to check the state of a given PictureBox by checking pbx.Image – as you do not have any custom attributes of the PictureBox.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's suppose I have a struct like this: struct my_struct { int a; int
Good afternoon all, I have a class which looks like this: public class Grapheme
Basically, I have a block of memory allocated using malloc that I want to
That may sound a little confusing. Basically, I have a function CCard newCard() {
I'm creating an output in Java using printf() to create table headers. One of
i'm trying to do video windowing that is: show all frames from a video
I have an application in which a user can pass in some or all
I have a DataGrid whose dataProvider is an Array of int Arrays (each with
This is my JFrame code: public static int width = 800; public static int
I have a stored procedure (sproc) called resetflags. It takes an int parameter. Another

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.