views:

112

answers:

1

I have got a textbox on a form with a method being called from the txPredio_Leave event.

My problem is that is the user has focus on the textbox and then close the form by clicking the little X close icon in the top corner or by calling this.ActiveMdiChild.Close(); or by calling

    private void mnucerrarTodas_Click(object sender, EventArgs e)
    {
        foreach (Form form in this.MdiChildren)
        {
            form.Close();
        }
    }

The txPredio leave execute the method.. then i need doesn't excute this method when the form is closing.

i have think that one solution could be ask in leave event if form is closing

        private void txPredio_Leave(object sender, EventArgs e)
        {  
            if(!form is closing)//pseudo code
               Check_Load_Predio();
        }

or other solution could be

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {   
       //code for cancel the txPredio_Leave event
    }

Solution Here Doesn´t work for me. Then I need one solution for my problem. Thanks in advance

+2  A: 

Try removing the Leave handler in FormClosing.

EDIT: Like this:

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{   
    txPredio.Leave -= txPredio_Leave;
}
SLaks
I say that in my question, but i don't know the code for do that.
MaK