Menus and Sending Events to Parent Form? 
Author Message
 Menus and Sending Events to Parent Form?

Hi all,

I have a form called frmLogin which displays a login prompt.  If
successful, it'll bring up a MDI form called frmMain.

On frmMain there are several Menu Items including "Logoff".

If I click Logoff, how do I send a message/event back to calling form
frmLogin?

Here's how I call frmMain.vb from frmLogin.vb

                Dim Main As New frmMain()
                Me.Hide()
                Main.ShowDialog()
                Me.Close()

In summary, is there a way to pass an event, parameter, or return value
from frmMain when I close it (or click the Logoff Menu selection).  Thanks.

--

Please delete "REMOVE" from the e-mail address when replying.



Sun, 05 Jun 2005 13:34:49 GMT  
 Menus and Sending Events to Parent Form?


Quote:
>Hi all,

>I have a form called frmLogin which displays a login prompt.  If
>successful, it'll bring up a MDI form called frmMain.

>On frmMain there are several Menu Items including "Logoff".

>If I click Logoff, how do I send a message/event back to calling form
>frmLogin?

>Here's how I call frmMain.vb from frmLogin.vb

>                Dim Main As New frmMain()
>                Me.Hide()
>                Main.ShowDialog()
>                Me.Close()

>In summary, is there a way to pass an event, parameter, or return value
>from frmMain when I close it (or click the Logoff Menu selection).  Thanks.

I guess you're after a method of hiding the main window and showing
the login window when someone clicks log-off, yes?

Previously in VB, you could do something like:

frmMain.Hide()
frmLogin.Show()

As the .Net model is slightly stronger, you're instance referencing
should be too. To be explicit, I like to use the following method in
all forms that are singleton to the application:

(In the login form code)
I add the following as a member (using your names as examples):

        Protected Shared m_Instance as frmLogin

And add the following method:

        Public Shared Function GetInstance() as frmLogin
                If m_Instance Is Nothing Then _
                        m_Instance = New frmLogin()
                Return m_Instance
        End Function

And add the following line into the New sub:

        Public Sub New()
                ...
                m_Instance = Me
                ...
        End Sub

Therefore, in the log-off menu click event handler, we can use the
code:

        Sub LogoffClicked(...)
                Me.Hide()
                frmLogin.GetInstance().Show()
        End Sub



Sun, 05 Jun 2005 20:31:10 GMT  
 Menus and Sending Events to Parent Form?


Quote:
> I guess you're after a method of hiding the main window and showing
> the login window when someone clicks log-off, yes?

Ah, thanks for this.  I need to read up on VB.NET.

But once I show a new instance of the the login form, how do I return
properties back to calling form (i.e. Login Failed, etc)?

--

Please delete "REMOVE" from the e-mail address when replying.



Mon, 06 Jun 2005 02:57:44 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing MDI Parents menu click events to child forms

2. Parent & Child Menu Click Events

3. Access Parent Form's Menu

4. How do I enable and disable menu items on the parent form

5. Linking Parent menus to specifc routines in child forms

6. Help on MDI Parent form's menu

7. ????Capturing MDI Child events in Parent Form

8. ????Capturing MDI Child events in Parent Form

9. ????Capturing MDI Child events in Parent Form

10. Check events on parent form?

11. Enabling Parent Menu based on Child Menus

12. Find out a sub-menu's parent menu

 

 
Powered by phpBB® Forum Software