Close Button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ali Rizwan
    Banned
    Contributor
    • Aug 2007
    • 931

    Close Button

    Hi all,
    We all have seen a close button on right side of title bar on any form in vb6.0
    I want that if i click on that button form doesn't terminate a timer control will enabled.
    Suppose if i click on close button a msgwill appear or a timer control will enabled true.
    But form will not terminated.
    Thanx
  • Dan2kx
    Contributor
    • Oct 2007
    • 365

    #2
    in excel there is a pice of code known as the Query_close procedure, i have no idea if it works in ur situation but i would do a search for that!

    Comment

    • Tig201
      New Member
      • Mar 2007
      • 103

      #3
      you can set Cancel to 1 in the form_unload and the form will not close.
      Code:
      Private Sub Form_Unload(Cancel As Integer)
        Cancel = 1
      End Sub
      Just be sure to put it in an If Satement so that you can close the form.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Generally it's better to use the Form_QueryUnloa d procedure, because this includes a parameter that tells you why the form is trying to unload (code, Windows shutting down, user clicked "close" button", etc.)

        Comment

        • Ali Rizwan
          Banned
          Contributor
          • Aug 2007
          • 931

          #5
          Originally posted by Killer42
          Generally it's better to use the Form_QueryUnloa d procedure, because this includes a parameter that tells you why the form is trying to unload (code, Windows shutting down, user clicked "close" button", etc.)
          Thanks Killer.
          But how to use it? I have never used this command.
          Thanks
          Last edited by Killer42; Oct 12 '07, 09:30 AM.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by Ali Rizwan
            But how to use it? I have never used this command.
            You should be able to create the procedure easily enough, just by selecting Form in the left-hand drop-down box (top of the code window), then choosing QueryUnload in the right-hand one.

            Then try posting in this code to demonstrate what's going on.

            [CODE=vb]
            Select Case UnloadMode
            Case vbFormControlMe nu
            ' User attempting to close the window.
            MsgBox "Hah! You can't get me that way."
            Cancel = True
            Case vbFormCode
            ' Unload was invoked from my code. Probably should allow it.
            Case vbAppWindows
            ' Windows is ending. Probably should allow it. You
            ' might want to ask "save before exiting?" or something.
            Case vbAppTaskManage r
            ' Task Manager is closing me. Probably that pesky user again!
            MsgBox "Nope! Give up, I'm not going anywhere."
            Cancel = True
            Case vbFormMDIForm
            ' Um... this only applies to MDI child forms.
            Case vbFormOwner
            ' Form is closing because its owner is closing.
            ' Whatever that means...
            End Select[/CODE]

            Comment

            • jamesd0142
              Contributor
              • Sep 2007
              • 471

              #7
              There is a form closed method which you can use for this.

              Double-click your form, and change the form load to form closed in the combo box on the top right of your code.

              Thanks
              Last edited by Killer42; Oct 14 '07, 03:53 AM.

              Comment

              • vdraceil
                New Member
                • Jul 2007
                • 236

                #8
                If you don't want the form to unload on clicking the close button, it is same as having no close button at the top. Try setting ClipControls and Controlbox properties of the form to false and set form's caption=""
                Last edited by Killer42; Oct 14 '07, 03:54 AM.

                Comment

                • ThaDu
                  New Member
                  • Oct 2007
                  • 1

                  #9
                  [CODE=vb]
                  Private Sub Form_Unload(Can cel As Integer)
                  MsgBox "A"
                  Timer1.Enabled = True
                  Cancel = 1
                  End Sub
                  Private Sub Timer1_Timer()
                  End
                  End Sub[/CODE]

                  [email removed]
                  Last edited by MMcCarthy; Oct 13 '07, 12:32 PM. Reason: email removed - against site rules

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Originally posted by jamesd0142
                    There is a form closed method which you can use for this.
                    Not in VB6, there isn't.

                    Comment

                    • jamesd0142
                      Contributor
                      • Sep 2007
                      • 471

                      #11
                      Originally posted by Killer42
                      Not in VB6, there isn't.
                      Once again im not using that version sorry.
                      visual basic 2005 express edition 'forClosed' and im sure its the same in vb.net, or very simular anyways.

                      Is there any other way of running code when the user closes the form ??

                      Thanks

                      in vb.net and vb 2005 express edition this works...
                      [code=vb]
                      Private Sub Form1Closing(By Val sender As System.Object, ByVal e As System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing

                      If MessageBox.Show ("Are you sure to exit?", "Exit", MessageBoxButto ns.YesNo, MessageBoxIcon. Question) = DialogResult.Ye s Then
                      e.Cancel = False
                      Else
                      e.Cancel = True
                      End If

                      End Sub
                      [/code]

                      Comment

                      • Killer42
                        Recognized Expert Expert
                        • Oct 2006
                        • 8429

                        #12
                        In VB6 (which Ali did mention) I believe you're limited to the Form_QueryUnloa d and Form_Unload event procedures.

                        Comment

                        Working...