开发者

C# closing another form problem, Close(); does not work

I have this code on form1

TimerMode f2 = new TimerMode();
f2.show();

now I'm trying to use this code in some point in time, but nothing happens? Cmd = Closing

public void DoActions(string Cmd)
{
  switch(Cmd){

  case"Open":
      TimerMode f2 = new Time开发者_如何学编程rMode();
      f2.show()
      break;
  case"Closing":
       f2.Close();
       break;
}
}

do you have any idea why its not closing?.

what I really want it to close it.

in vb6 I use this

unload form2


Most probably a threading issue. Try this:

f2.Invoke((MethodInvoker)(() => f2.Close()));

If that doesn't work, use below modification:

public TimerMode f2 = new TimerMode();
public void DoActions(string Cmd)
{
  switch(Cmd){    
  case"Open":          
      f2.show()
      break;
  case"Closing":
       f2.Close();
       break;
  }
}


I just spent hours wondering why my form wont close. Turns out, I forgot to check everything under

Debug->Exceptions

so one of the eventhandlers silently threw a NullPointerException that got caught by the Framework otherwise. I guess that sets the Cancel property of the event arguments to true and setting it to false afterwards does obviously not do the trick (When I fixed the NullPointer, everything worked normal again.).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜