Solved

Expose a User control event.

Posted on 2007-03-27
2
539 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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now