create MouseOver event at runtime...
I have a form that depending on results from a table would create a number of buttons using code at runtime. This could range from 1 to 20 buttons. What I am struggling with is creating a generic mouse over event for each of these buttons? The reason why I want a generic mouseover event is that depending on the text on the button I would do certain things, instead of duplicating the same code in individual mouseover events.
Is anyone able to give me some help with this. I am writing in VB.Net
Thanks in advance
Simon
Re: create MouseOver event at runtime...
Hope this helps
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mytop As Integer = 10
For index As Integer = 0 To 2
Dim btn As New Button
btn.Text = index.ToString
btn.Tag = "btn" & index.ToString
AddHandler btn.Click, AddressOf BtnClick
mytop += 30
btn.Top = mytop
Me.Controls.Add(btn)
Next
End Sub
Private Sub BtnClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim btn As Button = TryCast(sender, Button)
If btn.Tag = "btn0" Then
MessageBox.Show("button 1 clicked")
End If
End Sub
Re: create MouseOver event at runtime...
For more information about creating control array in VB.NET, read this topic.