• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

how to make only one ohbject of a form at a time in vb,net

I am wokring on a vb.net project and in that I have two forms.
One is mdi parent form and second is the child of first form.
So when I open the second through first form using menus.
I want that if the second form is alrady open then a message shuld come that says like the form is already open.

So how to do it
In samiple words I want only insatance of second form at a particular time.
And the seond instance should make when the firt one is distroed.

And also I have this code and I want to know whcih class should I import in my class to use this code below

dim app as SQLDMO.Application
app = new SQLDMO.ApplicationClass
dim names as SQLDMO.NameList
names = app.ListAvailableSQLServers()
dim i%
for i = 1 to names.Count
   cboServers.Items.Add names.Item(i)

1 Solution
Alexandre SimõesManager / Technology SpecialistCommented:

For the first question, just use the following code before you actually create the form you want to show:

            For Each f As System.Windows.Forms.Form In Me.MdiChildren
                If TypeOf f Is myForms.Form1 Then
                    System.Windows.Forms.MessageBox.Show("Form already open")
                    Exit Sub
                End If
            '*** Place your form creation code here ***

where myForms.Form1 is the form you want to show.
This will prompt you a messagebox informing that an instance of that form is already open and will exit the sub, skiping the creation code.

----- // -----

For the SQLDMO problem...

Go to your project references, Add a new COM Reference : Microsoft SQLDMO Object Library

That's all...

Alex :p


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now