Results 1 to 18 of 18

Thread: me.show vs me.visible = true

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    me.show vs me.visible = true

    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
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: me.show vs me.visible = true

    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.

  3. #3

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: me.show vs me.visible = true

    Quote Originally Posted by DigiRev
    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 know
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: me.show vs me.visible = true

    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!

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: me.show vs me.visible = true

    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."
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: me.show vs me.visible = true

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    New Member
    Join Date
    Apr 2020
    Posts
    7

    Re: me.show vs me.visible = true

    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!!!!

  8. #8
    New Member
    Join Date
    Apr 2020
    Posts
    7

    Re: me.show vs me.visible = true

    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!!!!

  9. #9
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,915

    Re: me.show vs me.visible = true

    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.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  10. #10
    New Member
    Join Date
    Apr 2020
    Posts
    7

    Re: me.show vs me.visible = true

    Quote Originally Posted by Elroy View Post
    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.
    Yes, you are absolutely right. 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.

    Thank you a lot
    Greetings from Greece!!

  11. #11
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: me.show vs me.visible = true

    I am doubting this statement:

    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.
    I would assume if you close all forms in the forms collection, it will go away (hidden or not).

    Ex (in main form unload):

    Code:
    dim f as form
    for each f in Forms
       unload f
    next

  12. #12
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,915

    Re: me.show vs me.visible = true

    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:

    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
    
    
    EDIT: If you're in the IDE, you've still got the IDE's "stop" button. But that's no longer true once compiled.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  13. #13
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: me.show vs me.visible = true

    tested:

    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
    Nothing remains 'running'. So, don't know the problem....

  14. #14
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,915

    Re: me.show vs me.visible = true

    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
    
    
    Last edited by Elroy; Apr 22nd, 2020 at 11:09 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  15. #15
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: me.show vs me.visible = true

    Yeah....so, doesn't EVERYBODY do this???? :-)

  16. #16
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,915

    Re: me.show vs me.visible = true

    Quote Originally Posted by SamOscarBrown View Post
    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.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  17. #17
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: me.show vs me.visible = true

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  18. #18
    New Member
    Join Date
    Apr 2020
    Posts
    7

    Re: me.show vs me.visible = true

    Quote Originally Posted by SamOscarBrown View Post
    I am doubting this statement:



    I would assume if you close all forms in the forms collection, it will go away (hidden or not).

    Ex (in main form unload):

    Code:
    dim f as form
    for each f in Forms
       unload f
    next

    Yes, i meant without using any other code for closing forms. Like the one you provide, for example...
    Bad coding, but i wanted to be clarified.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width