Solved

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

Posted on 2002-03-04
4
2,410 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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 - Capture pressed key onclick 4 41
VBA Shell can't Find Word document 11 110
Protecting vb6 & .Net code Obfuscation 18 150
Sub or Function is not defined 6 43
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

808 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