Solved

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

Posted on 2002-03-04
4
2,396 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now