form Closes with no reason?!?! Plaes Help!!


i had the same problem as this one had:

and this is my code:

  Private Sub qcPassed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles qcPassed1.Click, qcPassed2.Click

        Dim btn As Button = CType(sender, Button)

        Select Case btn.Name
            Case "qcPassed1"
                qcPassed1.ForeColor = Color.Green
                qcPassed2.ForeColor = Color.DarkBlue
                qcPastedvar = 1

            Case "qcPassed2"
                qcPassed2.ForeColor = Color.Red
                qcPassed1.ForeColor = Color.DarkBlue
                qcPastedvar = 2
        End Select

    End Sub

but for some reason after i pass the code, the form closes. no errors jest closed.

Now i'm loading my form from Sub Main()

but if i'm starting with my form directly it works well.

Why is that?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Your code in Sub Main looks like this?

Application.Run(New Form1)
RivKinAuthor Commented:
Dim frm As Form

        frm = New frmQC

Bob LearnedCommented:
What does Form.AcceptButton equal?

PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Diego PazosCommented:
I guess you set a DialogResult for the button. As a side effect, that causes the form to close.
To avoid it, just explicitly set the DialogResult for the form inside the button's code.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RivKinAuthor Commented:

 uKER: thats that was it. i was wondering what it does, and forgot about it.

so what does it do?

Diego PazosCommented:
The common use for a dialog is the following:
- Call a method that shows the dialog modally (i.e. locking execution until the dialog exits).
- Optionally, do something inside the dialog (choose a file, a colour, printer settings, you name it).
- Press some button that closes it (out of various possible ones).
- Query the dialog's DialogResult which informs about the outcome of the dialog.

The DialogResult evaluates to values such as OK, Cancel, Retry, Yes, No, etc, which you can then use to decide the course of your program.
A very clear example in case you're interested is the builtin OpenFileDialog.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.