0

In vb.net application , I open the form2 from form1 by btn event with following code.
But if the user minimise it and again open it from the button event, there are 2 forms in the taskbar...
I want the same form2 is opened everytime without multiplication of forms in taskbar.
How can i do that?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        Dim frm2 As New Form2
        frm2.Show()

    End Sub
3
Contributors
3
Replies
12
Views
1 Year
Discussion Span
Last Post by Satyam_1
0

You need to check if th form does exist and if it does set the window.state to normal. Something like this:

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim frmCollection = System.Windows.Forms.Application.OpenForms
        For Each f As Form In frmCollection
            If f.Name = "Form2" Then
                MsgBox("Form exists")
                f.WindowState = FormWindowState.Normal
                Exit Sub
            End If
        Next
        Dim form2 As New Form
        form2.Show()
        form2.Name = "Form2"
         form2.Text = "Form2"
    End Sub

Edited by Minimalist

This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.