Solved

Expose a User control event.

Posted on 2007-03-27
2
543 Views
Last Modified: 2012-06-21
How do I expose an event on a user control.  I have a user control with some textboxes on a form control.  There are some leave events in the usercontrol itself (totaling the textboxes).  Is there a way that I can catch this event from the main form so I preform some other action on the main form?  
0
Comment
Question by:Kevin Robinson
2 Comments
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18799688
well in this can u have to use raiseevent.
and in main form you have to handle/catch this method/event
0
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 total points
ID: 18799944
Here's a quick example.  The example UserControl has a single textbox on it that will have it's Leave event relayed back to the main form:

Public Class UserControl1
    Inherits System.Windows.Forms.UserControl

      Public Event TextBoxLeave(ByVal TheTextBox As TextBox)

      Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
            RaiseEvent TextBoxLeave(sender)
      End Sub

End Class

In your main form's code, you can catch the event like this:

      Private Sub UserControl11_TextBoxLeave(ByVal TheTextBox As System.Windows.Forms.TextBox) Handles UserControl11.TextBoxLeave
            MsgBox(TheTextBox.Name & " has thrown the Leave event")
      End Sub
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question