Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a 5 forms: frmLogin, frmOptionSelect, frmMenu, frmStaff and frmCompany

The first startup form is frmLogin. After login, user will go to frmOptionSelect. The code I made is Dim the frmOptionSelect as new form,show the form and Me.hide. This also I made in frmOptionSelect to call frmMenu.

Ok, on frmMenu I add 2 button; btnStaffDet and btnCompny. When user click btnStaffDet, I will call frmStaffDetails and place it onto the frmMenu. This is my code:

VB
Private Sub btnStaffDet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStaffDet.Click

     Dim frmStaffDet As New frmStaffDetails()
     frmStaffDet.TopLevel = False
     Me.Controls.Add(frmStaffDet)
     checkOpenForm(frmStaffDet)
     frmStaffDet.Show()
     frmStaffDet.Location = New Point(2, 149)

End Sub


The checkOpenForm is use to check which form is open on frmMenu.If there is any, it will close it and display the called form on it. This is the code for checking any opened form:

VB
Private Sub checkOpenForm(ByRef openform As Windows.Forms.Form)

   For i As Integer = My.Application.OpenForms.Count - 1 To 0 Step -1
       If My.Application.OpenForms.Item(i) IsNot Me Then
           My.Application.OpenForms.Item(i).Close()
       End If
   Next i

End Sub



Right now, could anyone lead me to the right code which it will only check the open form in frmMenu and not the whole apps? Because right now, when it check the open forms, it check the Login and Option Select form and because it only hide, it will close the forms but nothing displayed in Menu form. Please help..
Posted

1 solution

maybe this can help you
when displaying the form below frmMenu, such frmStaff and frmCompany, you should use the following code:
frmStaff.Show (Me)
"Me" is a form frmMenu, will be used when performing filter checkOpenForm.
use the property "Owner" to see who his parents when calling the function checkOpenForm,
"OpenForms (x). Owner ()"

See the following code to check the form

Private Sub checkOpenForm (ByRef openform As FormCollection)
As New Form1 Dim formParent
On Error Resume Next
As Form For Each oForm In openform
And if oForm.Owner isnot formParent oForm.Owner isnot Nothing Then
oForm.Close ()
else
oForm.Show ()
end If
Next
formParent.Dispose ()
end Sub
 
Share this answer
 
Comments
Luiey Ichigo 17-Apr-12 2:04am    
I'm sorry Hendra..I can't find a solution..I've tried it.thanks for helping
Hendra Yudha P 17-Apr-12 3:48am    
why you using Me.Controls.Add(frmStaffDet) to show the form?
Luiey Ichigo 18-Apr-12 23:21pm    
because I add the new form inside the current form and set new point location when it show..so that's why I use Me.blaa3...i've try before where the startup page is the menu, it can be done. But when the startup page is login, it can't display which it will close the login form(because when call form Menu, it will hide the login page with Me.Hide correct? I've try to close the login form but it will end the application before the Menu display)..That's why bro I want a code which check the open form within the Menu form only,not the entire program

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900