Sunday 15 September 2013

c# - Focusing on winform if already opened? -


I need to focus on the form if it has already been opened and I want to open a new look.

I have tried this code to solve my problem, but it opens the new form rather than focusing on the already opened form.

  foreach (different items in the application. Openform) {form form 1 = item as form; If (form1! = Null) {form1.Activate (); break; } Other {form1 = new form (); Form1.Show (); break; }}    

My guess This problem is that you Only really looking in the first form - you got a break statement in both parts of the if statement ... and you are just using it for normal Type

type which is almost certainly inappropriate. You want:
  var form = application OpenForm. Optty Type & lt; MyForm & gt; (). FirstOrDefault (); If (form! = Null) {form.Activate (); } And (new) MyForm () Show (); }    

No comments:

Post a Comment