Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create action on dynamically created button

Status
Not open for further replies.

mainit123

Technical User
Jan 24, 2005
25
0
0
I am adding a button to a form at runtime:

Dim formabc as New Form()
Dim newbut as New Button()
newbut.Text = "Go for it"
newbut.Location = New Point (100,100)

formabc.Controls.Add(newbut)

I am sorry if this sounds simplistic but how can I now add any action for this button if I can't get out of this subroutine that I am in, where I am creating the button?

I want this button to obviously do something but I have no way to get going with a "Click" action that I would normally have if I had hard coded the button into the form originally. That is, I don't know how to start assigning activity to the newbut button click event at this point.
If I just create one as

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

I am told I need a WithEvents Variable ????

Thanks for any replies.
 
thread796-1249818

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top