Solved

How to tell if a form is loaded in VB.Net

Posted on 2002-03-04
4
2,412 Views
Last Modified: 2007-12-19
I'm just upgrading to vb.net from vb6. In vb6 I had a great function that would tell me if a form was loaded. However, theres *no* equivalent to the forms collection.

I'd appreciate being able to keep my function paramter the same (form name as a string) but this isn't essential.

Any ideas folks?


'*********************************************************
'** FUNCTION:    IsFormLoaded
'** DESCRIPTION: Test if a form is loaded
'**
'** PARAMETERS:  Form name (string)
'**
'** RETURN:      true or false
'*********************************************************
Public Function IsFormLoaded(ByVal s_FormName As String) As Boolean

Dim i_FormCount As Integer
Dim t As Integer
   
    s_FormName = LCase(s_FormName)
    i_FormCount = Forms.Count
   
    For t = 0 To i_FormCount - 1
        If LCase(Forms(t).Name) = s_FormName Then
            IsFormLoaded = True
            Exit Function
        End If
    Next t
           
    '* must be false
    IsFormLoaded = False
   
End Function
0
Comment
Question by:GrahamAtJobserve
4 Comments
 
LVL 9

Accepted Solution

by:
kprestage earned 50 total points
ID: 6839175
In order to get the functionality of the Forms collection in .Net, you will need to implement your own Forms collection.  Basically, you will need a global Collection called Forms.  In each of your forms Contructor method, you would need to add the form to the forms collection.  In each dispose method, you would need to remove the form from the collection.  Wish I had a better answer for you, but this is the only way around this that I have heard of!

0
 
LVL 12

Expert Comment

by:guidway
ID: 7306304
This question appears to have been abandoned. A Moderator will be asked to
close this question after seven days, with the following recommended
disposition:

Points to kprestage

If you have any comment or objection to the recommendation, please leave it here.

guidway
EE Cleanup Volunteer
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7331666
Per recommendation, force-accepted.

Netminder
CS Moderator
0
 

Expert Comment

by:sqdperu
ID: 33212568
In VB.net 2005 I do this.  It also checks to see if it is minimixed and if it is I restore it first.

 
Private Sub OnTimePerformanceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OnTimePerformanceToolStripMenuItem.Click

        If frmOnTime.CanFocus = True Then
            If frmOnTime.WindowState = FormWindowState.Minimized Then
                frmOnTime.WindowState = FormWindowState.Normal
            End If
            frmOnTime.Focus()
        Else
            frmOnTime.Show()
        End If

    End Sub

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 92
Copy a row 12 69
Hide vba in gp 7 113
"Failed to convert parameter value from a String to a Decimal." 4 29
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question