Solved

Expose a User control event.

Posted on 2007-03-27
2
544 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Regex validation 2 28
Help with error when uploading excel file 3 38
export data table to excel in vb.net 10 36
Name Space error VS2015 1 25
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

861 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