By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Determine if a form is displayed?

P: n/a
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.
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Michael,

What kind of form?

MDI, dialog, normal

Cor
Nov 20 '05 #2

P: n/a
* "Michael D. Ober" <mdo.@.wakeassoc..com> scripsit:
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).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3

P: n/a
Usually a Dialog, but it could also be normal.

Mike.

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eK**************@TK2MSFTNGP09.phx.gbl...
Michael,

What kind of form?

MDI, dialog, normal

Cor

Nov 20 '05 #4

P: n/a
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
Nov 20 '05 #5

P: n/a
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.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:e9**************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #6

P: n/a
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
///


Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.