Solved

public event usage

Posted on 2009-05-06
3
157 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

12 Experts available now in Live!

Get 1:1 Help Now