Validating Opened Form Under MDI Form

Santosh4u
Posted by Santosh4u under Windows Forms category on | Views : 2303
hi All
I am giving the code ,how to validate form Opened or Not??
Explanation:
Let under my MDI Parent 6 forms are there,if i opened a form called(frmTest1) and if again i am trying to open same before closing that form then instead of open again it will show the opened form from task Bar.
if some of forms are opened in TaskBar,then u r trying to close the MDI Parent then it will show a message like "Some Forms are Already Opened"
To Validate above things,below VB.NET code will very helpful to you.

Public Class MDIForm
Dim objfrmCurMst As frmCurrencyMst
Dim frmCountMst As New frmCountrymst
Dim frmPortMst As New frmPortMst
Dim frmRegMst As New frmRegionMst
Dim frmStaMst As New frmStaffMst
Public objArrayList As New ArrayList()
Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles
NewToolStripMenuItem.Click
Try
If frmCountMst Is Nothing Then
frmCountMst = New frmCountrymst
objArrayList.Add(frmCountMst)
frmCountMst.Show()
Else
If frmCountMst.IsDisposed Then
frmCountMst = New frmCountrymst
End If
objArrayList.Add(frmCountMst)
frmCountMst.Show()
frmCountMst.Activate()
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly)

End Try
End Sub

Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs) Handles
OpenToolStripMenuItem.Click
Try
If objfrmCurMst Is Nothing Then
objfrmCurMst = New frmCurrencyMst
objArrayList.Add(objfrmCurMst)
objfrmCurMst.Show()
Else
If objfrmCurMst.IsDisposed Then
objfrmCurMst = New frmCurrencyMst
End If
objArrayList.Add(objfrmCurMst)
objfrmCurMst.Show()
objfrmCurMst.Activate()
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly)

End Try
End Sub

Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim SaveFileDialog As New SaveFileDialog
SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
SaveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"

If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = SaveFileDialog.FileName
' TODO: Add code here to save the current contents of the form to a file.
End If
End Sub


Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles ExitToolStripMenuItem.Click
For Each obj As Object In objArrayList
If Not obj Is Nothing Then
If CType(obj, Form).IsDisposed = False And CType(obj, Form).Visible = True Then
MsgBox("Some screens are Opened,Please Save and close",
MsgBoxStyle.Information)
Exit Sub
End If
End If
Next
Me.Close()
End Sub
Private m_ChildFormNumber As Integer = 0

Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ToolStripMenuItem1.Click
Try
If frmPortMst Is Nothing Then
frmPortMst = New frmPortMst
objArrayList.Add(frmPortMst)
frmPortMst.Show()
Else
If frmPortMst.IsDisposed Then
frmPortMst = New frmPortMst
End If
objArrayList.Add(frmPortMst)
frmPortMst.Show()
frmPortMst.Activate()
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly)

End Try
End Sub

Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SaveToolStripMenuItem.Click
Try
If frmRegMst Is Nothing Then
frmRegMst = New frmRegionMst
objArrayList.Add(frmRegMst)
frmRegMst.Show()
Else
If frmRegMst.IsDisposed Then
frmRegMst = New frmRegionMst
End If
objArrayList.Add(frmRegMst)
frmRegMst.Show()
frmRegMst.Activate()
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly)

End Try
End Sub

Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ToolStripMenuItem2.Click
Try
If frmStaMst Is Nothing Then
frmStaMst = New frmStaffMst
objArrayList.Add(frmStaMst)
frmStaMst.Show()
Else
If frmStaMst.IsDisposed Then
frmStaMst = New frmStaffMst
End If
objArrayList.Add(frmStaMst)
frmStaMst.Show()
frmStaMst.Activate()
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly)

End Try
End Sub

Ragards
Santosh

Comments or Responses

Login to post response