frmViewAll.DefInstance.Hide()

  • Thread starter Thread starter jeff
  • Start date Start date
J

jeff

I am attempting to be able to show and hide a form called viewAllForm.
I declared an instance of the form in a module.
Public viewAllForm As New frmViewAll

However I keep getting runtime errors when I close and try and show it
again. What is the proper way to do this? I only want 1 open at a time.
They can cover it up and leave it open if they want. But whenever they
click to show it I want it to come to the surface and/or to load if it
is not loaded. I do not know the best way to do this in VB.NET. In VB6
I would just do a frm.Show
 
I have 2 solutions:

---------------------------------------------------------------------
This way clears the form everytime.

Declare in the module:

Public viewAllForm As frmViewAll

' -- Everytime you want to show the form, create a new instance.

viewAllForm = New frmViewAll

' -- To hide it, close it.

viewAllForm.close


-------------------------------------- OR ---------------------------
This way you will still have information on the form. e.g. textboxes,
datagrids, etc.

Declare in Module:
Public viewAllForm As New frmViewAll

' -- Show the form
viewAllForm.Show

' -- Hide the form:
viewAllForm.hide

Does this help? Let me know :).
 
The first method creates a new form each time. I only want ONE.

The second method is basically what I am doing and seems very unstable
for some reason. For example if it is already displayed and you show
again, then it seems like it causes a runtime error. Any ideas?
 
Are you using 'Form.Hide' to close the form?


The first way will show only one form. Since you close the form with
'Form.Close', you dispose the object (clear it form memory). That's why you
have to create a new form.

--
Thiele Enterprises - The Power Is In Your Hands Now!

--
The first method creates a new form each time. I only want ONE.

The second method is basically what I am doing and seems very unstable
for some reason. For example if it is already displayed and you show
again, then it seems like it causes a runtime error. Any ideas?
 
I am attempting to be able to show and hide a form called viewAllForm.
I declared an instance of the form in a module.
Public viewAllForm As New frmViewAll

However I keep getting runtime errors when I close and try and show it
again. What is the proper way to do this? I only want 1 open at a time.
They can cover it up and leave it open if they want. But whenever they
click to show it I want it to come to the surface and/or to load if it
is not loaded. I do not know the best way to do this in VB.NET. In VB6
I would just do a frm.Show


FWIW:
I have a similar issue. I want to show a modal form and then hide it each time the
user is through with the dialog. With a main form and a "empty" dialog form, the
Hide statement works as expected. However, when I add a few controls, some code, and
a third party control, "Hide" does not work properly. The third party control techs
tell me that it's a known bug with "Hide". So, at the moment I'm having to open a
new instance of the dialog each time it's called and will have to revisit this when
the service pack is released and see it the issue was resolved.

Gene
 
I tried this. But if I try and call show when a form is still open it
will crash. How can I tell if the form is open already?
viewAllForm.Show()
 
Iterate through the open forms. Try this:

Dim FoundForm as Boolean = False
For Each myForm in My.Application.OpenForms
if myForm.Name = "whatever" Then
FoundForm = True
Exit For
End If
Next

Robin S.
 
I tried that but I could not figure out what to put in place of My in
the My.Application.OpenForms I tried everything from project name, to
solution name and even tried without it and just start with
Application.OpenForms but it did not work. What is My?
 
Oops. Are you using .Net2003? The MY namespace is only available in
VS2005/.Net2.0 Framework. Sorry about that.

Robin S.
 
What should I do then? Also, is there a better forum that I should be
using? Also, is there anything wrong with .NET 2003, do I need to do
any updates to make my code secure? I have heard some things about
insecure code. Also, what do I need to do on the compile for public
release? Anything special?

Also, how do I make my software work on as old of framework as
possible? And what DLLs and what websites should I point them to if
they have trouble running my software? Thanks.
 
I don't have .Net 2003, so I don't know how to access the
collection of open forms -- anyone else?

I also can't answer your other q's for the same reason.
This is the right forum to post them. Hopefully someone
else can help.

I don't know if there's anything "wrong" with .Net2003.
I'm just moving from VB6 to .Net, so I started with the
most current version. It has a lot of neat features not
available in 2003. Micro$oft put a lot more effort into
the Windows Forms aspect of the development tool. Apparently
they thought SmartClient apps were going to go away, so
they put all their effort into Web stuff for the earlier
versions of .Net, but they realized they were mistaken
and corrected themselves.

Good luck; sorry I didn't have an answer for you.
Robin S
 
OK, Sorry I was in a move, and had no WWW for a few weeks. To answer your
question. If you want to show another form, Just declare it new.

Dim f1 as new FrmViewAll

by declare it new, you are allocating the memory for this form.

Open the form.

f1.open

Close the form. (clreas the memory)

f1.close

------------------------------------
Also,

You can try to alter the new statement to load the form with variables.

Try this:

Public sub new (info as string, i as integer)
label1.text = info
label2.text = i
end sub

Does this help? Try to email me. I may be able to help you.
--
Thiele Enterprises - The Power Is In Your Hands Now!

--
I am attempting to be able to show and hide a form called viewAllForm.
I declared an instance of the form in a module.
Public viewAllForm As New frmViewAll

However I keep getting runtime errors when I close and try and show it
again. What is the proper way to do this? I only want 1 open at a time.
They can cover it up and leave it open if they want. But whenever they
click to show it I want it to come to the surface and/or to load if it
is not loaded. I do not know the best way to do this in VB.NET. In VB6
I would just do a frm.Show


FWIW:
I have a similar issue. I want to show a modal form and then hide it each
time the
user is through with the dialog. With a main form and a "empty" dialog
form, the
Hide statement works as expected. However, when I add a few controls, some
code, and
a third party control, "Hide" does not work properly. The third party
control techs
tell me that it's a known bug with "Hide". So, at the moment I'm having to
open a
new instance of the dialog each time it's called and will have to revisit
this when
the service pack is released and see it the issue was resolved.

Gene
 
Back
Top