Runtime Event Handler Giving Trouble

The Beginner

Member
Joined
Nov 25, 2009
Messages
6
Programming Experience
1-3
Hi,

I am having a strang problem with button event handlers that I am creating at runtime. Actually if I set the form as startup form everything is working fine but when I set the main apllication form as startup form the events for buttons created at runtime are not firing.

I am posting the code so that you can have a better look and see whts wrong?

I have two classes under spotlight here "Class1" and "Grid"

I am creating an instance of grid in class 1 and in a sub in grid I am creating buttons dynamically as follows and adding event handlers

For i As Integer = lIndex To uIndex
Dim btn As New Button
btn.Name = ds.Tables(tblName).Rows(i)(btnName).ToString
btn.Text = ds.Tables(tblName).Rows(i)(btnText).ToString
btn.Width = 72
btn.Height = 72
btn.FlatStyle = FlatStyle.Flat
btn.FlatAppearance.BorderSize = 0
btn.TextAlign = ContentAlignment.MiddleCenter
btn.Image = Image.FromFile("Images/prod.png")
btn.ImageAlign = ContentAlignment.MiddleCenter

Add Handler
AddHandler btn.Click, AddressOf Class1.BtnProduct_OnClick

Adding button to Table Layout Panel flp.Controls.Add(btn)

Next

As I mentioned before it is working fine if I set Class1 as the statrtup form but if this form is shown through another form, events don't work...:mad:

Showing this form like this at another button click event

Me.Hide()
Dim c1 As New Class1
c1.Show()

Pls help.....!
 
Thanx a lot. This solved the problem... I was feeling so dizzy after googling for three days but couldn't find anything that could help me. Thanx a lot once again... My problem's solved...
 

Latest posts

Back
Top