Results 1 to 12 of 12

Thread: [RESOLVED] Check if the Form is running or not

  1. #1

    Thread Starter
    Hyperactive Member vincentg's Avatar
    Join Date
    Jun 2005
    Location
    Chicago IL, USA
    Posts
    261

    Resolved [RESOLVED] Check if the Form is running or not

    Guys,

    Do you know a way to check if a specific form is running? Just like similar to VS 6.0 Forms Collection.

    The forms are not a MDI Child at all and this is Windows application only.

    Thank you. Prefered coding in C# but VB.Net is ok also.
    -vince

  2. #2
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Check if the Form is running or not

    Why not try a message box or a log - jennifer

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Check if the Form is running or not

    Try something like
    Code:
    private void button1_Click(object sender, System.EventArgs e) 
    { 
    Form form2; 
    
    if(m_arrFormList.Count > 0) 
    { 
    form2 = (Form)m_arrFormList[0]; 
    
    if(!form2.IsDisposed) 
    { 
    if(form2.WindowState == FormWindowState.Minimized) 
    form2.WindowState = FormWindowState.Normal; 
    form2.Activate(); 
    return; 
    } 
    else 
    m_arrFormList.RemoveAt(0); 
    } 
    
    form2 = new Form2(); 
    m_arrFormList.Add(form2); 
    form2.Show(); 
    }

  4. #4

    Thread Starter
    Hyperactive Member vincentg's Avatar
    Join Date
    Jun 2005
    Location
    Chicago IL, USA
    Posts
    261

    Re: Check if the Form is running or not

    Array?... i was looking to a similar Forms property also like that w/c is
    Form.OwnedForms Property but

    I dont know if this is the best solution...
    And if there is a Variable Object Collection w/c i will loop though it and see if a certain Form reference is running or not....

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Check if the Form is running or not

    Well if you want your own forms collection you could make one, just add a form to it whenever you load it.

  6. #6

    Thread Starter
    Hyperactive Member vincentg's Avatar
    Join Date
    Jun 2005
    Location
    Chicago IL, USA
    Posts
    261

    Re: Check if the Form is running or not

    .Net has no equivalent to Forms Collection.

    http://msdn.microsoft.com/library/de...alBasicNET.asp

    :P

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Check if the Form is running or not

    Yes, now refer back to my post #5 ...

  8. #8

    Thread Starter
    Hyperactive Member vincentg's Avatar
    Join Date
    Jun 2005
    Location
    Chicago IL, USA
    Posts
    261

    Re: Check if the Form is running or not

    I know and I read it already up to the
    Walkthrough: Creating Your Own Collection Class

    http://msdn.microsoft.com/library/de...ctionClass.asp

    Just thinking w/c is better.
    Your familiar with OwnedForms?
    I dont know if this is a good one also.

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Check if the Form is running or not

    Do you have C# 2005? If so you could use a generic List to contain your forms.
    Code:
    using System.Windows.Forms;
    using System.Collections.Generic;
    
    // ....
    public List<Form> Forms;

  10. #10

    Thread Starter
    Hyperactive Member vincentg's Avatar
    Join Date
    Jun 2005
    Location
    Chicago IL, USA
    Posts
    261

    Re: Check if the Form is running or not

    not installed yet.. but vs C# 2003, i had it here..
    using System.Collections.Generic; <--- is this a lot better?

    Planning to do the collection class w/c every time run a form i will just add it there and put something in the close event of the form to remove it.

  11. #11

    Thread Starter
    Hyperactive Member vincentg's Avatar
    Join Date
    Jun 2005
    Location
    Chicago IL, USA
    Posts
    261

    Re: Check if the Form is running or not

    anyways, thanks for the feed back guys!

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] Check if the Form is running or not

    Pre-2005 you needed to write your own Collection classes if you wanted to use strong binding, in VS 2005 you can use the classes in the Generic namespace. Generic-typed classes are strongly-bound at compile time to the type you specify. So it's equal to writing your own Forms collection class, without you having to do all the work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width