title: How do I raise a button click event for my class
body: <p>I have created a class to hold other objects. I need each object to be clickable. The following code works when I click on the objects using the mouse. However, I would like to simulate a mouse click by raising the mouseclick event from another function but I can figure out the syntax.</p>
  
  <p>This is my custom class:</p>
  
  <pre><code>Public Class MyTab
  
          Inherits System.Windows.Forms.Panel
          Public myText As New Label
  
          Public Event OnButtonClick As EventHandler
  
          Public Sub New(TextString)
              myText.Font = CustomFont.GetInstance(Main.main_font_size_up3, FontStyle.Regular)
              myText.ForeColor = Color.FromArgb(255, 0, 0, 0)
              myText.BackColor = Color.Transparent
              myText.Text = TextString
              Dim textSize As Size = TextRenderer.MeasureText(TextString, myText.Font)
              myText.Width = textSize.Width + 15
              myText.Height = textSize.Height + 6
              myText.UseCompatibleTextRendering = True
              myText.BorderStyle = BorderStyle.None
              myText.Name = "tab_" &amp; TextString
  
              Me.Width = textSize.Width + 10
              Me.Height = 30
              Me.BackColor = Color.White
  
              myText.TextAlign = ContentAlignment.MiddleCenter
              AddHandler myText.Click, AddressOf OnLabelClick ' Listen for the click on the new label
              AddHandler myText.MouseClick, AddressOf OnLabelClick ' Listen for the click on the new label
              Controls.Add(myText)
  
         End Sub
  
          Private Sub OnLabelClick(sender As Object, e As EventArgs)
              RaiseEvent OnButtonClick(Me, e)
              gray_out_tabs()
              sender.BackColor = Color.FromArgb(255, 255, 255, 255)
          End Sub
  
          Private Sub gray_out_tabs()
              ' gray out all tabs
              For Each item As Object In tab_holder.Controls
                  If TypeOf item Is MyTab Then
                      item.myText.BackColor = Color.FromArgb(255, 200, 200, 200)
                  End If
              Next
          End Sub
  
      End Class
  </code></pre>
  
  <p>I am trying to raise the mouseClick event on this class from another class but it is not working.</p>
  
  <p>This is my other class that I am trying to use:</p>
  
  <pre><code> Public Class myTabHolder
  
          Inherits Panel
  
          Public Function highlight(which)
  
              For Each item As Object In tab_holder.Controls
                  If TypeOf item Is MyTab Then
                      If item.mytext.name = "tab_" &amp; which.ToString Then
                          item.mytext.MouseClick() ' &lt;-- not working
                      End If
                  End If
              Next
              Return Nothing
          End Function
  
      End Class
  </code></pre>
  
  <p>I am not getting an error, but it is just ignoring my statement.</p>