Sunday, September 11, 2016

VB Beginner: How to open child form in parent form and activate if it already existed

This is how to control your form in Visual Studio. Actually, most of beginner programmers are very headache with working with forms and its interaction. Here is the great source code and tutorial on how to control forms.

Example:

 Private Sub btnChild1_Click(sender As Object, e As EventArgs) Handles btnChild1.Click
        Dim myForm As New frmChild1
        Try
            If Application.OpenForms.OfType(Of frmChild1).Any Then
                Application.OpenForms.Item("frmChild1").Activate()
            Else
                myForm.MdiParent = Me
                myForm.TopMost = True
                'myForm.WindowState = FormWindowState.Maximized
                myForm.Show()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End Try
    End Sub



Download source code for free: Children Form Control
Notice: This script is working find with Visual Studio 2012/2015 and later

0 comments :

Post a Comment