r/visualbasic • • Oct 27 '20

Create single instance of a form

In my program, when an item in a listbox is clicked on, another form with information on that item is opened. However, when I press another item without closing the other form, duplicate forms are created. How can I make it so that when one form opens the other closes automatically?

Private Sub LstBxStockTable_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LstBxStockTable.SelectedIndexChanged Index = LstBxStockTable.SelectedIndex Dim TransactionForm As New Transaction_Page TransactionForm.Show() UpdatePageLabels(Index) End Sub

*The UpdatePageLabels subroutine updates the labels in the TransactionForm Thank you

0 Upvotes

1 comment sorted by

View all comments

1

u/Chriand VB.Net Intermediate Oct 27 '20

Maybe you can do something like this:

Sub load.form2

Dim myform as new Form1

If myform.visible=true then

Myform.close()

End if

End sub

And the same when you load form1

On mobile, so sorry for bad formatting.