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 6733863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:49:14+00:00 2026-05-26T10:49:14+00:00

Hey all i have created dynamic buttons at runtime and i would like to

  • 0

Hey all i have created dynamic buttons at runtime and i would like to disable them when a user clicks on a form button.

This is the code i have for that button:

Dim intXX As Integer = 0

Do Until intXX = intX
    userAvatar(intXX).Enabled = False
    intXX = intXX + 1
Loop

The buttonNames is an array of all populated button names created at runtime. However, trying the .enabled = false at the end of that does not work. What other ways are there to do that with buttons created at runtime?

How i create the buttons are like this:

private sub createButton()
Dim personAvatar As New PictureBox

With personAvatar 
        .AutoSize = False                        '>                        ^

        If intX = 7 Then
            thePrviousAvatarImg = 0
        End If

        If intX <= 6 Then
            .Location = New System.Drawing.Point(10 + thePrviousAvatarImg, 10)
        ElseIf intX >= 7 And intX <= 14 Then
            .Location = New System.Drawing.Point(10 + thePrviousAvatarImg, 150)
        Else
            Exit Sub
        End If

        .Name = "cmd" & nameOfPerson
        .Size = New System.Drawing.Size(100, 100)
        .TabStop = False
        .Text = ""
        .BorderStyle = BorderStyle.FixedSingle
        .BackgroundImageLayout = ImageLayout.Center
        .BackColor = Color.LightGray
        .BackgroundImage = Image.FromFile(theAvatarDir)
        .Tag = nameOfPerson
        .BringToFront()
    End With

    AddHandler personAvatar.Click, AddressOf personAvatar_Click
    Me.Controls.Add(personAvatar)
    userAvatar(intX) = personAvatar
    intX = intX + 1
End With
End Sub

Thanks for your time and help!

David

  • 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-26T10:49:15+00:00Added an answer on May 26, 2026 at 10:49 am

    You can’t refer to button objects using a string representation of their names. Instead of using buttonNames (which I assume is an array of strings), use an array of buttons and add each button to that. Then loop through that array (as you’ve done here) setting enabled = false on each one.

    So before you create each picture box, declare an array to store them:

    Dim MyPictureBoxes() as PictureBox
    

    Then as you create each one, add them to the array. When you’re done creating them, you can disable them like this:

    For Each MyPictureBox In MyPictureBoxes
        Debug.Print(MyPictureBox.Name)
        MyPictureBox.enabled = False
    Next
    

    I’ve created a form with two buttons, cmdGo and cmdDisable, to demonstrate this more completely:

    Public Class Form1
        Dim MyPictureBoxes(4) As PictureBox
    
        Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGo.Click
            Dim personAvatar As New PictureBox
            Dim intX As Integer = 0
    
            While intX < 5
                personAvatar = New PictureBox
                With personAvatar
                    .AutoSize = False
                    .Left = intX * 100
                    .Top = 100
                    .Name = "cmd" & intX
                    .Size = New System.Drawing.Size(100, 100)
                    .TabStop = False
                    .Text = ""
                    .BorderStyle = BorderStyle.FixedSingle
                    .BackgroundImageLayout = ImageLayout.Center
                    .BackColor = Color.LightGray
                    .BringToFront()
                End With
    
                Me.Controls.Add(personAvatar)
                MyPictureBoxes(intX) = personAvatar
                intX = intX + 1
            End While
        End Sub
    
        Private Sub cmdDisable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDisable.Click
            For Each MyPictureBox In MyPictureBoxes
                Debug.Print(MyPictureBox.Name)
                MyPictureBox.Enabled = False
            Next
        End Sub
    End Class
    

    Notice how MyPictureBoxes is scoped for the whole form so it’s accessible to both subs.

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

Sidebar

Related Questions

Hey all. So I have a collection of csv files which I would like
Hey all - I have an app where I'm authenticating the user. They pass
Hey everyone, running into a bit of an issue, I have created all my
Hey all, I have created a WinForms to handle Persistence Activities using the Windows
hey all I have tables with millions of rows in them and some of
Hey all,(im a beginner in rails) i've created a controller that look like that:
Hey all, I have something of an interesting requirement for my project. I need
Hey all. I have a server written in java using the ServerSocket and Socket
Hey all. I have a question on how to implement the following with Django.
Hey all, I have been doing nothing but web development over the last few

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.