PC Review


Reply
Thread Tools Rate Thread

how to check if a form is already open

 
 
TM
Guest
Posts: n/a
 
      25th Feb 2004
Is there any way to check if a form is already pen and if so set the focus
to it instead of opening another instance of that form ?

Thanks
--
Tony




 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      25th Feb 2004
Hi Tonny,

> Is there any way to check if a form is already pen and if so set the focus
> to it instead of opening another instance of that form ?


Hi Tonny, sorry that I have to write this, but this is the answer.

"Use good program logic"

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      25th Feb 2004
* "TM" <nospam-(E-Mail Removed)> scripsit:
> Is there any way to check if a form is already pen and if so set the focus
> to it instead of opening another instance of that form ?


Have a Google Search for "Singleton Design Pattern".

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet/>
 
Reply With Quote
 
Chris Morse
Guest
Posts: n/a
 
      25th Feb 2004
On Tue, 24 Feb 2004 23:59:17 -0500, "TM" <nospam-(E-Mail Removed)>
wrote:

>Is there any way to check if a form is already pen and if so set the focus
>to it instead of opening another instance of that form ?
>
>Thanks


It's not very easy. You could use Win API functions to enumerate all
windows and look for the window in question. (eg, EnumThreadWindows)

I had hoped that the static .NET function
System.Windows.Forms.Form.ActiveForm() would help me determine if ANY
forms were open besides the "main" form.

Unfortunately, I found it had a few quirks that limited its usefulness
for me:

(1) ActiveForm returns "Nothing" if the application does not
have focus.
(2) .. Returns "Nothing" if a non-application form is being
displayed (eg, a MsgBox() is open)

I think that you'll have to either resort to a windows enumeration or
building the functionality by adding code to implement the "singleton"
design pattern.

// CHRIS

 
Reply With Quote
 
TM
Guest
Posts: n/a
 
      25th Feb 2004
Sorry but that is not an answer. I am new to .Net and have no idea how to
do this in vb.net.

I have a button to add a new record into the database which opens a form
with the fields and such.

I want to prevent someone from opening that form more than once
--
Tony



"Cor" <(E-Mail Removed)> wrote in message
news:upW4st3%(E-Mail Removed)...
> Hi Tonny,
>
> > Is there any way to check if a form is already pen and if so set the

focus
> > to it instead of opening another instance of that form ?

>
> Hi Tonny, sorry that I have to write this, but this is the answer.
>
> "Use good program logic"
>
> Cor
>
>



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      25th Feb 2004
Hi Tony,

Use good program logic was the answer.

What is not good on it. There are so many logical methods for that.
One sample.

If you want to prevent that the form is opened twice you set that button to
invisible and set it to visible if the form is closed.

Very easy and simple programming logic.

Cor





 
Reply With Quote
 
Chris Morse
Guest
Posts: n/a
 
      27th Feb 2004
On Wed, 25 Feb 2004 14:27:48 -0500, "TM" <nospam-(E-Mail Removed)>
wrote:

>Sorry but that is not an answer. I am new to .Net and have no idea how to
>do this in vb.net.
>
>I have a button to add a new record into the database which opens a form
>with the fields and such.
>
>I want to prevent someone from opening that form more than once
>--
>Tony


In that case, just define the form normally and call it like this:

Dim myForm As New FormName
myForm.ShowDialog()

Then the user interface will be essentially disabled until the user is
done with the form... a basic "modal" form..

// CHRIS

 
Reply With Quote
 
dakine181
Guest
Posts: n/a
 
      4th Mar 2006

Cor wrote:
> *Hi Tonny,
>
> > Is there any way to check if a form is already pen and if so se

> the focus
> > to it instead of opening another instance of that form ?

>
> Hi Tonny, sorry that I have to write this, but this is the answer.
>
> "Use good program logic"
>
> Cor *



Only registered to reply to this post. I was looking for similia
answers/solutions.Felt compelled to reply to it even though it's suc
an old post.

This kind of post doesn't help one bit. It's like a teacher you ha
back in school you asked for help on a spelling of a word. Thier repl
is look it up in the dictionary.

i've got a helpful reply

'Go seek the holy grail' thats were you will find your answer

Suffice to say this post was no f****** help at all and just someone
lazy 'I'm better than you' poor attitude.

Dakin


-
dakine18
-----------------------------------------------------------------------
Posted via http://www.mcse.m
-----------------------------------------------------------------------
View this thread: http://www.mcse.ms/message423947.htm

 
Reply With Quote
 
New Member
Join Date: Apr 2006
Posts: 3
 
      4th Apr 2006
aye, that cor seems a bit of a knob

try this TM;

Private WithEvents newMDIchild1 As frmNewForm
'this section above the windows form designer generated code


Private Sub miAboutOpen_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles miAboutOpen.Click
If Me.newMDIchild1 Is Nothing Then
Me.newMDIchild1 = New frmAbout
End If
newMDIchild1.MdiParent = Me
newMDIchild1.Show()
hidePanel()
End Sub
Private Sub miAboutClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miAboutClose.Click
If Me.newMDIchild1 Is Nothing Then
Me.newMDIchild1 = New frmAbout
End If
newMDIchild1.MdiParent = Me
newMDIchild1.Hide()
hidePanel()
End Sub
 
Reply With Quote
 
New Member
Join Date: Apr 2006
Posts: 3
 
      4th Apr 2006
aye, that cor seems a bit of a knob

try this TM;

set the IsMdiContainer property of your main form to true, this sets it as the mdi parent (multiple document interface)
get yourself a menu item and create open and close links on it then double click each of the menu items and replicate the code below - obviously using your own form names in stead of frmNewForm.

Private WithEvents newMDIchild1 As frmNewForm
'this section above the windows form designer generated code


Private Sub MenuItem1Open_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MenuItem1Open.Click
If Me.newMDIchild1 Is Nothing Then
Me.newMDIchild1 = New frmNewForm
End If
newMDIchild1.MdiParent = Me
newMDIchild1.Show()
End Sub
Private Sub MenuItem1Close_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MenuItem1Close.Click
If Me.newMDIchild1 Is Nothing Then
Me.newMDIchild1 = New frmNewForm
End If
newMDIchild1.MdiParent = Me
newMDIchild1.Hide()
End Sub

this should work a treat for ya mate.

once again, cor is a knob

cheers y'all
Ray
 
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
Check If Form Open or Not kirkm Microsoft Excel Programming 2 7th Mar 2008 12:32 AM
Check if a form is open? Mike Microsoft Access 1 8th Jun 2005 12:47 PM
How to check if a form is open Pele Microsoft Access Macros 0 23rd Nov 2004 10:05 PM
check to see of a form is open Karen Microsoft Access Form Coding 2 9th Aug 2004 07:01 PM
How can I check if a form is open Paul Microsoft Access Form Coding 2 4th Aug 2004 03:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:29 AM.