Determine if a form is displayed?

  • Thread starter Thread starter Michael D. Ober
  • Start date Start date
M

Michael D. Ober

In VB 6, you can query the forms collection to see if a form is loaded and
then check that form's window state to find out if it's displayed or not.
How can a VB.Net program tell if a form is displayed? Finding out it's load
state would be nice, but I really need to know if a form is on the screen.

Thanks,
Mike Ober.
 
* "Michael D. Ober said:
In VB 6, you can query the forms collection to see if a form is loaded and
then check that form's window state to find out if it's displayed or not.
How can a VB.Net program tell if a form is displayed? Finding out it's load
state would be nice, but I really need to know if a form is on the screen.

Your form could implement the Singleton design pattern (see Google for
more info).
 
Hi Michael,

When a dialog is open, it loses only the focus when it is closed, so when
you are in another form you are sure that it is closed.

A form is not "loaded" anymore as in VB6, the form handling in that was a
little bit strange to make things easy I have readed here.

So try first why you need it and check than if it still is your problem.
(The approaches for all three forms are different)
Usually a Dialog, but it could also be normal.

I hope that I understand your question well, otherwise reply, however please
with a concrete problem.

Cor
 
We have ~150,000 lines of VB 6 code that will need to eventually ported to
VB.Net. Littered throughout this code is a variant of the conditional

if isLoaded("someform") then
do something with someform
else
do something else with someform
end if
....
someform.hide (or unload someform)

"someform" is usually, but not always a status message form. In some cases
it's a keyboard handling form. In others, it's simply been hidden to allow
access to it's current state and/or application specific public methods and
properties. There are even a few cases where someform is a "form" variable
that gets loaded and dumped with the scope of the referencing code, but I'm
not worried about these right now as these will be the last to be ported.

I'm aware that many of these programs will require serious rework - to the
extent of dumping the old code entirely in a couple of cases, but if there
is some way to identify when a form is in memory, that would be great.

Mike.
 
Hi Michael,

And you are sure it is not a MDI, because that is really totaly different
from the rest.

With a normal form it is more difficult, when you do not hide it.
I can give you this sample however I doubt that it helps you.

Cor

\\\form1
Private WithEvents frm3 As New Form3
Private WithEvents frm2 As New Form2
Private Sub frm2_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm2.VisibleChanged
If frm2.inputfield <> "" Then
Me.Show()
Me.Label1.Text = frm2.inputfield
frm2.Dispose()
End If
End Sub
Private Sub frm3_VisibleChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles frm3.VisibleChanged
If frm3.inputfield <> "" Then
Me.Show()
Me.Label1.Text = frm3.inputfield
frm3.Dispose()
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
frm3.Show()
frm3.TopLevel = True
frm2.Show()
frm2.TopLevel = True
End Sub
///
\\\form2 and 3 the same
Public inputfield As String
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

inputfield = "sometext"
Me.Hide()
End Sub
///
 
Back
Top