Close 'X' button problem on child form

Post smallest amount of code of a single Form that reproduces this. By default clicking the x will close the form.


Answer this question

Close 'X' button problem on child form

  • Segua

    Are you still having this problem

    Thanks,
    Karen

  • lingling

    All of the child forms have a common factor and that is they all use while loops.  I am collecting a ton of serial data and looping works best.  Does the loop have something to do with it, I would expect the App.doevents() to handle the event correctly when it fires.  Below you will find the constructor, MyForm_Method, which contains the while loop and a timer to trigger the method once the constructor is done.
    Thank you.

    public MyForm()
    {
    // Required for Windows Form Designer support

    InitializeComponent();
    //TODO: Add any constructor code after InitializeComponent call

    timer1.Enabled =
    true;
    }




    void
    MyForm_Method()
    {
    timer1.Enabled =
    false;
     w
    hile(key_pressed == 0)
     {
     Application.DoEvents();
     }
    }

    private void MyForm_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    key_pressed = e.KeyChar;
    }

    private System.Windows.Forms.Timer timer1;

    int key_pressed=0;

    private void timer1_Tick(object sender, System.EventArgs e)
    {
    MyForm_Method();
    }


  • Close 'X' button problem on child form