Results 1 to 7 of 7

Thread: close button.....

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    99

    Exclamation close button.....

    can annyone help me on how to make a msg box showing wen some one tryes 2 leave the dialog box..


    sorry im new on programming ..

    please annyone help me
    Attached Images Attached Images  

  2. #2
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: close button.....

    This should work:

    VB Code:
    1. Private Sub OnExit(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closed
    2.         Dim dr As DialogResult
    3.         dr = MessageBox.Show("Are you sure you want to leave?", "Leave?", MessageBoxButtons.YesNo)
    4.         If dr = DialogResult.Yes Then
    5.             End
    6.         End If
    7.     End Sub

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: close button.....

    Actually you would handle the Closing event, or FormClosing in VB 2005 (please use the radio buttons provided to specify your IDE/Framework version when creating a thread), and Cancel the action if they choose not to leave.
    VB Code:
    1. Private Sub Form1_Closing(...) Handles MyBase.Closing
    2.     If MessageBox.Show("Are you sure you want to exit?", _
    3.                        "Vejeel Soft", _
    4.                        MessageBoxButtons.OKCancel, _
    5.                        MessageBoxIcon.Question) = Windows.Forms.DialogResult.Cancel Then
    6.         e.Cancel = True
    7.     End If
    8. End Sub
    Also, it is a subtle difference that many people seem not to notice but you should be using OK and Cancel on your buttons and not Yes and No.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: close button.....

    Quote Originally Posted by jmcilhinney
    Also, it is a subtle difference that many people seem not to notice but you should be using OK and Cancel on your buttons and not Yes and No.
    (not meant to be taken the wrong way) Why is that?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: close button.....

    Quote Originally Posted by francisstokes
    (not meant to be taken the wrong way) Why is that?
    Not taken the wrong way at all.

    Throughout the Windows interface, when the user requests an action and a confirmation dialogue box is displayed, the OK, Cancel, Yes and No buttons have specific meanings. OK means "do what I asked", Cancel means "don't do what I asked", Yes means "do what I asked plus something extra", No means "do what I asked but nothing extra". Take note of the dialogues that Microsoft products display and you'll see that whenever you are asked a question like "Are you sure you want to..." the buttons on the dialogue will be OK and Cancel. An appropriate use of Yes and No would be if the question was "Do you want to save your changes before exiting?" where Yes would mean save and close (do what I asked plus something extra) and No means close without saving (do what I asked but nothing extra). The fact that No and Cancel mean different things is evidenced by the fact that there is a Yes, No, Cancel button combination. You could use it in the previous example where Cancel would mean don't close (don't do what I asked). That demonstrates the difference between No and Cancel very clearly.

    Of course, there are other situations where Yes and No are appropriate, like if you were asking "Do you live in the United States?". I'm talking specifically about when the user requests an action and your message box is confirming that action.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    99

    Re: close button.....

    emmm wile im new on this was a bit hard fr me make that are you abble 2 send me a

    form file example for vb.net 2005 ?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: close button.....

    Doing it yourself is the best way to learn. There are two ways to add event handlers in VB 2005. You can open the code file and select the variable for the drop down list at the top-left and the event from the top-right. Alternatively you can select the object in the designer, go to the Properties window and press the Events button (lightning bolt) and then double-click the event you want to add a handler for. Either way you would select the FormClosing event for the form itself and then paste the contents of the method I posted previously into your event handler.
    Attached Images Attached Images  

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