Results 1 to 3 of 3

Thread: create MouseOver event at runtime...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    170

    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

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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
    Please mark you thread resolved using the Thread Tools as shown

  3. #3
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: create MouseOver event at runtime...

    For more information about creating control array in VB.NET, read this topic.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width