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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:00:26+00:00 2026-05-13T20:00:26+00:00

Using VB 2008 Express. Attaching code to buttons when they’re clicked is easy when

  • 0

Using VB 2008 Express.

Attaching code to buttons when they’re clicked is easy when they’re static buttons on the form; just double click the button on the form designer and add code to the event.

I have a series of buttons that are generated in a control array, so they’re generated in a class, and in the form there are no buttons until runtime.

So newbie question with a probably simple answer…how do I enter code for the click event for buttons that aren’t there until they’re instantiated as a class at runtime?

  • 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-13T20:00:26+00:00Added an answer on May 13, 2026 at 8:00 pm

    The way you would do it for regular buttons, I think.

    What action do you want to take on each of the buttons? If the action is different for each of the button, could you give an example of what it looks like?

    EDIT: Crude code ahead

       Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim button As Button()
            ReDim button(2)
    
            Dim button1 As New Button
            button1.Top = 0
            button1.Height = 100
            button1.Text = "hello"
    
            Dim button2 As New Button
            button2.Top = 200
            button2.Height = 100
            button2.Text = "world"
    
            button(0) = button1
            button(1) = button2
    
            For i As Integer = 0 To 1
                '** This is where all the buttons are tied, to a common handler
                AddHandler button(i).Click, AddressOf doSomething
            Next
    
            Me.Controls.AddRange(button)
        End Sub
    
    
        Protected Sub doSomething(ByVal sender As Object, ByVal e As EventArgs)
            Dim thisButton As Button
            thisButton = sender
    
            thisButton.BackColor = Color.DarkBlue
            thisButton.Text = "clicked"
        End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 501k
  • Answers 501k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use: SELECT DISTINCT sia.SuggestionItemID, STUFF((SELECT ','+ a.description FROM CSFT_Application a… May 16, 2026 at 2:11 pm
  • Editorial Team
    Editorial Team added an answer takes a deep breath We were looking into something to… May 16, 2026 at 2:11 pm
  • Editorial Team
    Editorial Team added an answer It looks like you have defined path and minpaths as… May 16, 2026 at 2:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm using sql 2008 express edition and I'm trying to do a multiple row
I am using VS 2008 WebDeveloper Express edition. And i'm developing a little aplication,
I am using VS 2008 Express. One of the projects I'm working on uses
I'm using VWD 2008 Express Edition with MVC and I am trying to add
I am using VC++ 2008 express edition for C. When I try to run
Exactly what the title says. I'm using MSVC++ 2008 express, and my class constructor
I am developing using VSTS 2008 + C# + .Net 3.5 + ASP.Net +
I have a SQL Server 2008 procedure that sends email via sp_send_dbmail. I'm using
I am using VS 2008. I have to create a wcf service and inside
I am using SSMS 2008 and trying to insert with this query but am

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.