Solved

Is the form hidden VB.Net 2005

Posted on 2009-05-10
7
262 Views
Last Modified: 2012-05-06
Hi,

How do you determine if a form is hidden or closed.  

I've tried using the "created" property but I'm getting mixed results.  If the form is closed and I try an "if formname.visible = false" type query then I get True where the form is hidden or closed.  I can put in a workaround but I'm ideally looking for an answer to this.

NB. A modification to the IsLoaded function below is required to capture hidden forms.
Function IsLoaded(ByVal Loadedfrm As Form) As Boolean
        Dim frm As Form
 
        For Each frm In My.Application.OpenForms
 
            If frm.Name Is Loadedfrm.Name Then
                IsLoaded = True
            Else
                IsLoaded = False
            End If
        Next
 
    End Function

Open in new window

0
Comment
Question by:geraintcollins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 15

Expert Comment

by:ChloesDad
ID: 24348411
What do you mean by a closed form, when you close a form, then the is no longer available unless code within the form is still running.  In VB6 you could close a form and still be able to access the form, you can't do that in .net.
0
 

Author Comment

by:geraintcollins
ID: 24350225
The difference is explained below.  Now how do you tell, say from another form or module in the application, whether form1 is closed or hidden?
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Hide()
    End Sub
End Class

Open in new window

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 24350336
Try something like this:

        If Not Form1.IsHandleCreated Then
            Label1.Text = "Form1 Closed"
        ElseIf Form1.Visible Then
            Label1.Text = "Form1 Open"
        Else
            Label1.Text = "Form1 Hidden"
        End If

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:ChloesDad
ID: 24350375
You can do me.close, but then you can't do me.show, as me has been closed, you would have to create a new copy of the form to be able to use it again

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.close.aspx
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24350379
*Unless you are working with the DEFAULT INSTANCE of the form...    ;)

0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 24352073
True, I had overlooked that as a possibility as its lazy programming, and if any of my staff do that I make them change it so that you only work with objects that you have created. I was surprised that they put that back in after omitting it from .net 2003, but thats another discussion....
0
 

Author Closing Comment

by:geraintcollins
ID: 31579899
Excellent, answered the question without getting stuck on the reason why, I appreciate that.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

628 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