Results 1 to 9 of 9

Thread: [RESOLVED] Allow a form to be minimized, but not closed

  1. #1

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Resolved [RESOLVED] Allow a form to be minimized, but not closed

    I am working on a program that will allow the user to disconnect from a VPN session. I don't want the users to close the form because then they wouldn't be able to disconnect (well wouldn't be able to do it easily).

    In other words, I want users to be able to minimize the form, but not be able to close it. If I use a BorderStyle of "none", can I still minimize it to the taskbar? I will have a button on the form that says "minimize" so I don't care about having the little minimize dash in the upper right of the form. If I can't have a borderless form that minimizes to the taskbar, does anyone know how I can accomplish it in another way?

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

    Re: Allow a form to be minimized, but not closed

    This will minimize if you try to close
    Code:
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Cancel = -1
    Me.WindowState = vbMinimized
    End Sub
    Of course, now, the only way to close this window is to log completely off the machine or shut the machine down or use the Task Manager to close it. Is that what you want?

  3. #3
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Allow a form to be minimized, but not closed

    I have a form like that that must stay open for the life my app and cannot be closed unless the main form is closing. So i put a public module level flag on the form that cannot be closed. eg; mAllowFormToClose set the flag to true when unloading the main form. Then

    Code:
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    if not mAllowFormToClose
    Cancel = -1 'stop form closing
    else
    cancel = 0 'allow the form to close
    end if
    End Sub
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  4. #4

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: Allow a form to be minimized, but not closed

    It's not that I want them to log off or use task manager to close it... if they click the 'disconnect' button that I have on the form, it will disconnect them vpn connection and end the program.

    Thanks for the help! I'm assuming that I can't use the "BorderStyle = None" and still be able to minimize it to the taskbar, right?

  5. #5

  6. #6

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: Allow a form to be minimized, but not closed

    Ok, very good information, but I'm wondering about the BorderStyle. I would prefer to use either None, or Fixed ToolWindow. The only problem is, these styles don't show up on the taskbar. Can I still somehow minimize them to the taskbar? The form will have a Minimize command button, but I'm thinking since it doesn't show in the taskbar when it's up on the screen, there's probably no way to minimize it to the taskbar, right?

  7. #7

  8. #8
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: Allow a form to be minimized, but not closed

    Alternatively:
    Code:
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Cancel = Not mAllowFormToClose
    End Sub

  9. #9

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: Allow a form to be minimized, but not closed

    Thanks everyone! I'd be lost without help from the experts!

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