Click here to Skip to main content
15,614,766 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:

I am working on window application in VB.Net. I do have a problem with
The scenario is-

suppose i have form1 with two buttons
button1.text = "one"
button2.text = "one"

I have another form2
i want to open form2 on each button click present on form1.

'click event on button1
Dim obj As New form2(button1.text)

'click event on button2
Dim obj As New form2(button2.text)

on form2
Public Sub New(ByVal ReceiveValue As String)
End Sub

Now every time i click on button1 or button2 a new form2 is open.

I want to open 1 form for button1 and 1 form for button2.
How do i prevent duplicate forms for each button1 and button2 if form is already open.


Everytime you create a new instance of the form a new one will open.

The best way to handle the problem is to allow another class (lets just say a controller class) to open both these forms for you. You can keep a track of the number of open forms inside this and control the number you want to be seen open on the screen.
Share this answer
thanks for the solution..

but i have done with my below solution

For Each CurrentForm As Form In Application.OpenForms
            If CurrentForm.Name = "form2" Then
              Dim Form2Instance As form2 = DirectCast(CurrentForm, form2)
              If Form2Instance.TextBox1.Text = "some text" Then
                Exit Sub
              End If
            End If

          Dim form As New form2("some text")
Share this answer

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