Greetings!

I have a problem with my dialog box, my project has multiple form. When I try to exit the dialog will appear, If will the OkButton the method function as what i want, but if I click CancelButton the from will close itself but the program is still running.

Dim dlg As DialogResult
        dlg = MessageBox.Show("Are you sure you want to exit?", "Warning!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
        If dlg = Windows.Forms.DialogResult.OK Then
            Me.Close() : Form1.Show()
            TeamBox.Items.Clear() : teamBox2.Items.Clear()
        else
            'Do nothing    
        End If

When CancelButton will be hit the current form will close but the project still running because of form1.

If Form1 is the startup form just call Form1.Close(). That will close the whole app.

But I want to still showing the current form. In me.close(), that's the time for form1.show(). In my case, im trying to escape from quiting the form.

Do you want the dialog to keep showing even after the cancel button is pressed?

Yeah, I do.

I'll need to see more of your code. The only dialog you're showing is the MessageBox.

This is my Exit procedure:

Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click, Cancelbtn.Click
        Dim dlg As DialogResult
        dlg = MessageBox.Show("Are you sure you want to exit?", "Warning!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
        If dlg = Windows.Forms.DialogResult.OK Then
            Me.Close() : Form1.Show()
            TeamBox.Items.Clear() : teamBox2.Items.Clear()
        else
        'Do nothing
        End If
End Sub

I also this in form1, and there's no problem about that. Does it matters the lines of codes. My codes are almost 3000 lines.

This should suffice. I'll just need to make sure I understand what you want. Do you want to show a dialog and hide this form when the cancel button is clicked?

MODIFIED:

Ok here, When a user click the cancel button DialogBox will prompt to ensure the decision of the user. If the user click's OK, then the current form will close and parent will show, but if the user clicks CANCEL nothing will happen the current form.
At first, this is okay. But when I change the KeyPreview = True and ControllBox = False, this problem occur. I have no hint in this trouble.

I'm sorry for my Bad english.

I'm understanding more now. So when Cancel is pressed on the messagebox is this form still closing? If so the problem is 2 fold I believe. First in this dialog form's properties change the CancelButton to none. Second in the designer file(i.e. Dialog1.Designer.vb), make sure this line is deleted,Me.Cancel_Button.DialogResult = System.Windows.Forms.DialogResult.Cancel. You may have to click the Show All Files button to see this file. This should stop the dialog from closing.

yeah that's it.
I will this thread solved if this will work. Thank's

You're welcome.

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.