Switching between forms

In a WinApp I have a startup page "frmRules" which displays information to users.  Upon them hitting the OK button, I open frmMainScreen like so:

        Dim frmMainScreen As New frmMainScreen
        frmMainScreen .Owner = Me
        frmMainScreen .Show()

I want for frmRules to complete hide when frmMainScreen loads, but on frmMainScreen I want a button that will bring it back up and place focus on it.  I just can'tseem to figure this out.
LVL 2
chrisryhalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shahan AyyubSenior Software EngineerCommented:
Below this line in frmrules:
frmMainScreen .Show()

write
Me.hide()

frmMainScreen will be appear and on frmMainScreen, on button event write:

        Frmrules.Show()

Is this helpful ????
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Just be aware that if you go back and forth multiple times then you will be creating multiple instances of frmMainScreen but will only be hiding/showing the same instance of frmRules.

To work with the same frmMainScreen everytime get rid of this line:

    Dim frmMainScreen As New frmMainScreen

Just depends on what your app does and how it should work.
0
jppintoCommented:
To open my child forms on top of a parent form, I use the attached funcion to do that. I call the function with something like this on the main form, when I click a button to open a child form:

Call OpenMDIForm(New frmInsertProduction, Me)

jppinto
Public Sub OpenMDIForm(ByVal frmName As Form, ByVal frmParent As Form, Optional ByVal frmTag As Integer = 0, Optional ByVal frmDuplicates As Boolean = False)
        Dim IsLoaded As Boolean = False
        Dim frm As Form

        On Error Resume Next

        ' In case Duplicate forms are not allowded
        If Not frmDuplicates Then
            ' Checks if it's already opened
            For Each frm In frmParent.MdiChildren
                If frm.Name = frmName.Name Then
                    IsLoaded = True
                    Exit For
                End If
            Next
        End If

        ' Case it's not open
        If Not IsLoaded Then
            frmName.MdiParent = frmParent

            'Sets the Tag value of the form
            If frmTag > 0 Then frmName.Tag = frmTag
            frmName.Show()

        Else
            frmName.Focus()
        End If

        frmName = Nothing
        frm = Nothing
    End Sub

Open in new window

0
PeterDimitrovCommented:
Create a property in frmMainScreen which will keep pointer to frmRules (I am using the name RulesForm , but you can use any other)

' code for the new property in frmMainScreen 
    Private _frmRules As System.Windows.Forms.Form
    Public Property RulesForm() As System.Windows.Forms.Form
        Get
            Return _frmRules
        End Get
        Set(ByVal value As System.Windows.Forms.Form)
            _frmRules = value
        End Set
    End Property

    'code to show frmRules form from frmMainScreen 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If _frmRules IsNot Nothing Then
            _frmRules.Show()
        End If
    End Sub

' code to show frmMainScreen  from frmRules ( your original code) + 1 line to set the new property value
       Dim frmMainScreen As New frmMainScreen
        frmMainScreen.Owner = Me
        frmMainScreen.RulesForm=Me  'set new property value to the current instance of frmRoles
        frmMainScreen.Show()
        Me.Hide()    ' hide frmRules

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.