944,069 Members | Top Members by Rank

Ad:
Aug 20th, 2007
0

How to check if form is open

Expand Post »
How do I check if a form is open (not only loaded, but also open)
Similar Threads
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Aug 20th, 2007
0

Re: How to check if form is open

Click to Expand / Collapse  Quote originally posted by plusplus ...
How do I check if a form is open (not only loaded, but also open)
What I mean is, I know how to check if it's loaded, but I want to know if it's being shown at this time
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Aug 20th, 2007
0

Re: How to check if form is open

Hi,

Copy this Function and Pass the form name. If form is loaded and not shown, then it's Visible property will be false, u need to check that:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub CheckFormStatus(Myform As Form)
  2. Dim objForm As Form
  3. Dim FlgLoaded As Boolean
  4. Dim FlgShown As Boolean
  5. FlgLoaded = False
  6. FlgShown = False
  7. For Each objForm In VB.Forms
  8. If (Trim(objForm.name) = Trim(Myform.name)) Then
  9. FlgLoaded = True
  10. If objForm.Visible Then
  11. FlgShown = True
  12. End If
  13. Exit For
  14. End If
  15. Next
  16. MsgBox "Load Status: " & FlgLoaded & vbCrLf & "Show Status:" & FlgShown
  17. End Sub

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Aug 20th, 2007
0

Re: How to check if form is open

Thank you , what you are saying is if it's loaded, check if its visible. Works perfectly. What is Trim in the code you gave me? I did it without, is there any reason it's needed?
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Aug 20th, 2007
0

Re: How to check if form is open

Hi,

If it is for ur Timer Form..(previous thread), then I suggest an alternative solution. When u show the subForm in Modal, Disable the Timer, And Enable the timer In UnLoad event of the subForm. This way u need not check if the form is loaded/visible and all the stuff..

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Aug 20th, 2007
0

Re: How to check if form is open

Hi,

Trim is not necessariy required, but just to be on the safer side, using Trim..

REgards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Aug 20th, 2007
0

Re: How to check if form is open

Thank you so much for that idea. My project is just getting bigger and bigger and every time I add another thing, I have to make sure it doesn't cause any problems to my old stuff. I'm at the end now and trying out every single possibility, to make sure it all works.
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Sep 17th, 2008
0

Re: How to check if form is open

Just put the following code in your form closing event (for vb.net (VS2008). For more detail http://developerskb.blogspot.com
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  2. If frmOrdDet.Visible = True Then
  3. MsgBox("Costing detail input form is in active! Close it before exit", MsgBoxStyle.Information)
  4. frmOrdDet.Focus()
  5. e.Cancel = True
  6. Else
  7. Dim dr As Object
  8. If e.CloseReason = CloseReason.UserClosing Then
  9. dr = MsgBox("Exit Application..?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question)
  10. If dr = vbYes Then
  11. frmLogin.Dispose()
  12. Me.NotifyIcon.Dispose()
  13. e.Cancel = False
  14. Else
  15. e.Cancel = True
  16. End If
  17. End If
  18. End If
  19. End Sub
Last edited by arbalu; Sep 17th, 2008 at 4:36 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
arbalu is offline Offline
4 posts
since Jul 2008
Mar 7th, 2009
0

Re: How to check if form is open

Thanks ur code worked for me....

Click to Expand / Collapse  Quote originally posted by QVeen72 ...
Hi,

Copy this Function and Pass the form name. If form is loaded and not shown, then it's Visible property will be false, u need to check that:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub CheckFormStatus(Myform As Form)
  2. Dim objForm As Form
  3. Dim FlgLoaded As Boolean
  4. Dim FlgShown As Boolean
  5. FlgLoaded = False
  6. FlgShown = False
  7. For Each objForm In VB.Forms
  8. If (Trim(objForm.name) = Trim(Myform.name)) Then
  9. FlgLoaded = True
  10. If objForm.Visible Then
  11. FlgShown = True
  12. End If
  13. Exit For
  14. End If
  15. Next
  16. MsgBox "Load Status: " & FlgLoaded & vbCrLf & "Show Status:" & FlgShown
  17. End Sub

Regards
Veena
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alaguvadi is offline Offline
1 posts
since Mar 2009
Jan 28th, 2011
0

You can always use SysCmd

I don't recall where I found this, but it works:

Public Function fncIsFormOpen(strFormName As String) As Boolean
If (SysCmd(acSysCmdGetObjectState, acForm, strFormName) = acObjStateOpen) Then fncIsFormOpen = True
End Function
Reputation Points: 10
Solved Threads: 0
Newbie Poster
muspench is offline Offline
1 posts
since Jan 2011

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: TreeView
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Help in making a project on ATM machine





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC