Solved

Expose a User control event.

Posted on 2007-03-27
2
545 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 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