PC Review


Reply
Thread Tools Rate Thread

Determine if a form is displayed?

 
 
Michael D. Ober
Guest
Posts: n/a
 
      13th Jul 2004
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.


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Jul 2004
Michael,

What kind of form?

MDI, dialog, normal

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      13th Jul 2004
* "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/>
 
Reply With Quote
 
Michael D. Ober
Guest
Posts: n/a
 
      13th Jul 2004
Usually a Dialog, but it could also be normal.

Mike.

"Cor Ligthert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Michael,
>
> What kind of form?
>
> MDI, dialog, normal
>
> Cor
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Jul 2004
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


 
Reply With Quote
 
Michael D. Ober
Guest
Posts: n/a
 
      13th Jul 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Jul 2004
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
///




 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine path to picture displayed in image control Andrew Microsoft Excel Programming 1 29th Sep 2009 01:42 PM
Form that is already displayed modally cannot be displayed as a modal dialog box. Close the form before calling showDialog. Jared Microsoft Dot NET Framework Forms 4 28th Sep 2006 09:49 AM
How to determine when a form is first displayed curtsfakeguy@hotmail.com Microsoft Dot NET Framework Forms 2 25th May 2006 11:23 PM
Determine currently displayed address? Bill James Microsoft Outlook VBA Programming 9 10th May 2005 09:04 PM
Determine which tab page is currently displayed =?Utf-8?B?UGFjbw==?= Microsoft Access Form Coding 2 3rd Jan 2005 01:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:50 PM.