Solved

public event usage

Posted on 2009-05-06
3
163 Views
Last Modified: 2013-11-07
I am having a little trouble with this as I have never used a public event.  I have one VB.net user control that acts like a form.  There is a button on this user control that calls another user control which is also displayed like a form.  this is not a modal.  We have an interface in  place that handles these usercontrols and puts them into tabs.  basically what I think I need to do is raise a public event that will in turn call a method on the calling user control when the called user control is saved.  Any ideas?
0
Comment
Question by:oak29
  • 2
3 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24318731
How is the first UserControl "calling" the second one?  Does it have a reference to it?...or is it raising an event that the Form catches and then "passes" on to the second?  If one has a reference to the other already then you should be able to subscribe to a custom event that the second usercontrol raises...
0
 

Author Comment

by:oak29
ID: 24318865
this is essentially as far as I have gotten.  This is not working


Calling usercontrol

I have this in the load of the calling form

Dim _CalledUserControl As CalledUserControl = New CalledUserControl ()
            AddCalledUserControl handler(_NoticeOfLoss)  --> Adding my event

These are two sub procedures in the calling form

Public Sub AddCalledUserControl (ByVal oCalledUserControl  As CalledUserControl )

        AddHandler oCalledUserControl.Event, AddressOf CallingUserControl_LoadMethod

    End Sub

    Private Sub CallingUserControl_LoadMethod()
        LoadMethod()  ---Method I am trying to call
    End Sub


I have this declared as Global in my Called user Control
Public Event Event()

I have this when I click my save changes button
RaiseEvent Event()
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 24414223
Ok...not sure I follow everything but here is an example of UserControl1 creating an instance of UserControl2 and subscribing to one of its custom events:

Public Class UserControl1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim uc2 As New UserControl2
        AddHandler uc2.MyEvent, AddressOf uc2_MyEvent
        uc2.Location = New Point(Button1.Location.X, Button1.Location.Y + Button1.Height)
        Me.Controls.Add(uc2)
    End Sub

    Private Sub uc2_MyEvent()
        MessageBox.Show("MyEvent() received from uc2!")
    End Sub

End Class

Public Class UserControl2

    Public Event MyEvent()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        RaiseEvent MyEvent()
    End Sub

End Class

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

785 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