Have had this in the back of my mind for a while, but am now gonna ask.
Is there any difference at all:
me.show or me.visible = True
me.hide or me.visible = False
Printable View
Have had this in the back of my mind for a while, but am now gonna ask.
Is there any difference at all:
me.show or me.visible = True
me.hide or me.visible = False
Yes, there is a difference.
I think .Show calls the ShowWindow() API function but not sure.
But say, if Form2 is minimized, and you set .Visible to false, it will be hidden. If you then set .Visible to True, it will be visible, but still minimized.
But if you just use: Form2.Show, it will restore from taskbar and become visible.
Thanks good to knowQuote:
Originally Posted by DigiRev
The big difference, to me, between .Show and .Visible is that .Show is used to load a form that is not currently loaded whereas .Visible makes visible a form that is loaded, but hidden.
BTW: Congrats on 4k DigiRev! :thumb:
The only difference that I know of...
.Show is a method
.Visible is a property
The Form.Show method is derived from the Control class.
From MSDN: "Showing the control is equivalent to setting the Visible property to true. After the Show method is called, the Visible property returns a value of true until the Hide method is called."
Also, don't forget that Show as other optional parameters. Visible does not.
For example. You can show a form and make it modal; you cannot do that with the visible property. Also toggling visible property on a modal form, breaks modality.
Sorry for ressurecting but
Also toggling visible property on a modal form, breaks modality.
This was the answer i had tried to found many-many days!!! THANK YOU LaVolpe!!!!
Sorry for ressurecting but
Also toggling visible property on a modal form, breaks modality.
This was the answer i had tried to found many-many days!!! THANK YOU LaVolpe!!!!
Toggling the .Visible property also breaks the form's owner.
So, the only difference I see between .Visible=True and .Show is that .Show allows you to set modality and allows you to set an owner (which is sometimes quite useful).
Now, regarding .Visible=False and .Hide, personally I can't see any difference at all. Both turn off modality and ownership, and both keep the form loaded but hide it. And neither do anything different with the COM instantiation of the form's code.
I am doubting this statement:
I would assume if you close all forms in the forms collection, it will go away (hidden or not).Quote:
Be aware that even if the App closes/exit, the hidden form remains in memory and you have to kill the application from task manager or press the stop button from the VB editor.
Ex (in main form unload):
Code:dim f as form
for each f in Forms
unload f
next
Hi Sam,
gcharal didn't say it well, but I think he just mean, even if you unload all the other forms, that .Visible=False (or frm.Hide) will still have a loaded form which will keep the program from terminating. And then, you've got a program that's running with no visible forms, and that is a Task Manager situation.
More like this... Start a new project, add a Form2, and then put this code in Form1:
EDIT: If you're in the IDE, you've still got the IDE's "stop" button. But that's no longer true once compiled.Code:
Option Explicit
Private Sub Form_Click()
Form2.Show
Form2.Hide
Unload Me
' After I unload, the app will still be executing but without any visible interface.
End Sub
tested:
Nothing remains 'running'. So, don't know the problem....Code:Option Explicit
Private Sub Form_Click()
Form2.Show
Form2.Hide
Unload Me
' After I unload, the app will still be executing but without any visible interface.
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim f As Form
For Each f In Forms
Unload f
Next
End Sub
Hi Sam ... Yes, you added that loop to the Form_Unload which cleaned up the problem. :)
EDIT: Also, I always try and run those "Delete" type loops backwards, as I'm never sure what the "Delete" (or, Unload, in this case) is going to do to the collection. It seems to work ok in this case, but, to me, it's more clear if we just run the loop backwards:
Code:
Dim i As Long
For i = Forms.Count - 1& To 0& Step -1&
Unload Forms(i)
Next
Yeah....so, doesn't EVERYBODY do this???? :-)
On a project with less than 10 forms, I don't. Personally, I'd rather see the project hung in the IDE, and then try to figure out what I did to cause that.
Admittedly, on my primary very large project (with 100s of forms), I do have such a loop. However, even there, I'll sometimes comment it out during development to figure something out. But I do leave it in whatever I compile, just in case the user finds some strange-novel way to contort things and leave a form loaded (but not visible) while exiting.
Sam, maybe I'm in a bit of a contrary mood these days, but this seems similar to turning on OERN at the top of every procedure. IDK, it just seems like we should work to make sure our code is doing precisely what we want it to ... and when we want to exit, we haven't forgotten about any hidden forms. ;)
That statement by gcharal is true, just not well stated.
If you simply hide a form, and forget to unload it, the project won't terminate because the form is still loaded, running or not. Reworded like that, I don't think there is any debate and is more clear.
In that particular case, app has 2 forms, the main form and some other one that was shown and then hidden, not unloaded. Now the user clicks the X on the main form thinking they terminated the application. Nope, that hidden form is keeping the process alive and needs to be terminated via task manager.
As Sam pointed out there are ways to ensure all forms are unloaded when the main form is closed. But a simple FYI that gcharal threw out there could be helpful for novices.