Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15714

5.0 Win forms extention method to Open Or show the existing instance to front

$
0
0
With win forms
i am trying to have an extension method to open OR show the existing instance of the form , if its already open.
but if the form is already open, it's not being presented at the front and activated,
However if its not working new instance is being presented correctly
what im doing wrong ?
vb.net Code:
  1. public static void OpenOrShowFrom(this Form f)
  2.         {
  3.             Boolean IsOpen = false;
  4.  
  5.             foreach (Form frm in Application.OpenForms)
  6.             {
  7.                 IsOpen = frm.Name == f.Name;
  8.  
  9.                 if (IsOpen)
  10.                 {
  11.                     break;
  12.                 }
  13.             }
  14.  
  15.             // If for is already open just bring it to front & Activate
  16.             // TODO: If form is already open , it's not being bring to front & activated ?
  17.             if (IsOpen)
  18.             {              
  19.                
  20.                 f.Activate();
  21.                 f.WindowState = FormWindowState.Normal;
  22.                 f.BringToFront();            
  23.                                
  24.             }
  25.             else // Other wise open new instance of the form
  26.             {
  27.                 f.Show();
  28.             }
  29.            
  30.  
  31.         }

Viewing all articles
Browse latest Browse all 15714

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>