none
Close Form

    Pregunta

  • I'm sure this has been asked a million times ... but here goes.

    Private Sub SimpleButton3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SimpleButton3.Click
             Me.Hide()
            TestMenu()
            Me.Close()
        End Sub

    The problem with this code is that it doesn't close until TestMenu() has been completed.  I would like it to close immediately.  What should I do.  Me.hide is a temp solution...but not what I want.

    lunes, 21 de mayo de 2012 13:09

Respuestas

  • Hello, I'm not sure on the best solution but a couple of things you might want to try are:

    See if just moving TestMenu() after Me.Close() still runs - best way to tell is in debug mode. I'm really not sure if the code will run once the form is closed, I think it should as the Click method hasn't completed yet but I'm not sure.

    Another option would be to use the form event FormClosed and run TestMenu() from in there - you could then just trigger Me.Close() in your button click event which would in turn fire the FormClosing and then FormClosed events.

    Either approach relies upon code still running after the form has closed which I would think will happen but I'm not 100% sure if it will as I've not tried it myself :P


    Nick Sandel (Software Tester) New to C# since December 2011

    lunes, 21 de mayo de 2012 13:19

Todas las respuestas

  • Hello, I'm not sure on the best solution but a couple of things you might want to try are:

    See if just moving TestMenu() after Me.Close() still runs - best way to tell is in debug mode. I'm really not sure if the code will run once the form is closed, I think it should as the Click method hasn't completed yet but I'm not sure.

    Another option would be to use the form event FormClosed and run TestMenu() from in there - you could then just trigger Me.Close() in your button click event which would in turn fire the FormClosing and then FormClosed events.

    Either approach relies upon code still running after the form has closed which I would think will happen but I'm not 100% sure if it will as I've not tried it myself :P


    Nick Sandel (Software Tester) New to C# since December 2011

    lunes, 21 de mayo de 2012 13:19
  • HI

    Why do you use ShowDialog method to show form

    and then invoke the TestMenu(),like following sample

    Form1 _form = new Form1();

    _form.ShowDialog();

    _form.TestMenu();


    DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.

    lunes, 21 de mayo de 2012 14:07
  • I'm sure this has been asked a million times ... but here goes.

    Private Sub SimpleButton3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SimpleButton3.Click
             Me.Hide()
            TestMenu()
            Me.Close()
        End Sub

    The problem with this code is that it doesn't close until TestMenu() has been completed.  I would like it to close immediately.  What should I do.  Me.hide is a temp solution...but not what I want.

    Is Me form the main form? The one started from Program class? If so, you cannot close it, since it has a reference of the main form. 

    Mitja

    lunes, 21 de mayo de 2012 14:38
  • I can't believe I didn't try that...simply moving TestMenu() after me.close works perfectly.

    Thanks...

    lunes, 21 de mayo de 2012 16:17