mario.deghetto

Visual Basic & .NET
posts - 332, comments - 79, trackbacks - 0

#3: [VB.NET] Verificare che un form sia aperto

Tip valido per le versioni dalla 2005 in poi.

Per verificare che un form sia aperto si può utilizzare il codice sotto riportato.
Aspetti fondamentali di questa tecnica sono:
- l’importazione del namespace System.Windows.Forms
- il ciclo di test sul nome del form realizzato con For Each,
testando la collezione Application.OpenForms.

 

Imports System.Windows.Forms
Public Class Form1
   Private Sub Button1_Click(ByVal sender As System.Object, _
           ByVal e As System.EventArgs) Handles Button1.Click
      Dim nomeForm As String = "Form1"
      If VerificaFormAperto(nomeForm) = True Then
         MessageBox.Show(nomeForm & " è aperto!")
      Else
         MessageBox.Show(nomeForm & " NON è aperto")
      End If
   End Sub
 
   Public Function VerificaFormAperto(ByVal nomeForm As String) _
         As Boolean
      Dim f As Form
      For Each f In Application.OpenForms
         If f.Name = nomeForm Then
            Return True
         End If
      Next
      Return False
   End Function
End Class  

Print | posted on domenica 11 ottobre 2009 5.58 |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 5 and 8 and type the answer here:

Powered by: