0

Maybe it's a silly question but I can't find a solution.

I have an MDI form with multiple children. There is one that I could say is the main one.

To detect that the principal is no longer used and another child form is used I use the 'Leave' event which works very well.

The problem is when from the mdi form, a modal type (.ShowDialog ()) is executed, the Leave event doesn't happen in the child form.

Any suggestion or comment on how to get it is welcome.

Fabián Romo
  • 319
  • 2
  • 14
  • Parent form is blocked while `ShowDialog()` is executing. Maybe [this](https://stackoverflow.com/a/33411037/12888024) may help. – aepot Jul 19 '20 at 08:33
  • @user3249244 , please add your sample code, and explain what you have tried. –  Jul 19 '20 at 14:41
  • @user3249244 I'm modifying the code that someone else did some time ago In the main child form there is a timer that tries to send a frame to a server approximately every 20 seconds. What I are trying to do is that when code pass to another form, this timer is deactivated. Between child forms is easy, since the 'Leave' event works fine, but when the mdi calls a modal form, I don't know how to detect from the "main" form that a modal form has been invoked. – Fabián Romo Jul 19 '20 at 15:47

2 Answers2

0

you can use this to just use the current class which is in your situation the (main) .

0

I solved it this way:

From the MDI form, from where the modal forms are called, I search for the child forms and if it is the "main" one, I call a public function that does the same as the Leave event of the "main" form:

foreach (Form childform in this.MdiChildren)
{
    if (childform.Name.Equals("MyMainForm"))
    {
        var formMain = (MyMainForm)childform;
        formMain.stopTimer();
    }
}

It may be a cumbersome solution, but it is functional.

Fabián Romo
  • 319
  • 2
  • 14