Hi all i hope this little code help some people.
This code is to make your program can't open 2 times so when you open your app and try to open it again a msgbox will pop up and wont let you open it again.

Dim CurrentProcesses() As Process
    Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)

        CurrentProcesses = Process.GetProcessesByName _
                           (Process.GetCurrentProcess.ProcessName)
        If CurrentProcesses.GetUpperBound(0) <= 0 Then
            Exit Sub
        End If

        Dim XMsg As String = "Here is what ever you want the msgbox say."
        MessageBox.Show(XMsg, _
                   "Here is the Title of the MsgBox", _
                   MessageBoxButtons.OK, _
                   MessageBoxIcon.Error)
        End
    End Sub

i hope i help you

You can use this too is less complicate.

Dim MymessageBox1
    Dim CurrentProcesses() As Process

Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)

        CurrentProcesses = Process.GetProcessesByName _
                           (Process.GetCurrentProcess.ProcessName)
        If CurrentProcesses.GetUpperBound(0) <= 0 Then
            Exit Sub
        End If
        MymessageBox3 = MsgBox("What ever you want it to say HERE", MsgBoxStyle.Critical, "MsgBox Title HERE")
        End
    End Sub

Or in your project you can goto the properties window and click the checkbox that says "Make Single Instance application"

\yeah i know
Yup but it wont tell you why you can't open it again,

Anyways both ways works
So...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.