Event at runtime

Posted on 2008-02-01
Medium Priority
Last Modified: 2013-11-26
Hello i am working in an windows application in which i have generated buttons at runtime i.e.
declare object of button and then add it on form now i have to do some event on click of those buttons so can you help me to suggest how to handle the event of button whose event name is not known
please help me
Thanks in advance
Question by:ASINGH1974
1 Comment
LVL 18

Accepted Solution

Joel Coehoorn earned 2000 total points
ID: 20798719
Declare the buttons "WithEvents" and use the AddHandler keyword:

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    ' button click event
End Sub

Dim WithEvents MyButton As New Button
' set button attributes and add to form
AddHandler MyButton.Click, AddressOf Button_Click

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question