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

Posted on 2005-05-15
Last Modified: 2010-04-17
I am wokring on a 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)

Question by:deepakyadav
    1 Comment
    LVL 30

    Accepted Solution


    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    Title # Comments Views Activity
    countTriple  challenge 8 59
    Sql how to exclude from a table 3 60
    copyEndy  challenge 15 37
    changeXy challenge 13 40
    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    A short article about a problem I had getting the GPS LocationListener working.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now