.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Validating To Opened Form Under MDI Form

Posted By:Santosh       Posted Date: October 08, 2009    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  
 

hi All

i am giving the code ,how to validate form Opened or Not??

Ex:
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 Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        'Use My.Computer.Clipboard.GetText() or My.Computer.Clipboard.GetData to retrieve
        information from the clipboard.
    End Sub




    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub TileVerticleToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As
    EventArgs)
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As
     EventArgs)
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Close all child forms of the parent.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    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


NiCE Coding

Ragards
Santosh
http://santoshdotnetarena.blogspot.com/


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend