Solved

public event usage

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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