?
Solved

public event usage

Posted on 2009-05-06
3
Medium Priority
?
168 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
[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
3 Comments
 
LVL 86

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 86

Accepted Solution

by:
Mike Tomlinson earned 750 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 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