Results 1 to 6 of 6

Thread: Disable Close button

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Disable Close button

    For all those who are interested, I have posted some code in the CodeBank that will disable the Close button on the title bar of a form. I don't know if it's been seen before but I've not heard mention of it and I'm too lazy to search.

    http://www.vbforums.com/showthread.php?t=351541
    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

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Disable Close button

    Like this from yesterday?

    http://www.vbforums.com/showpost.php...1&postcount=12



    - ØØ -

  3. #3

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Disable Close button

    Quote Originally Posted by NoteMe
    If you check the CodeBank you'll see that the code gets rid of the bath water (Close button) but leaves the baby (title bar, system menu, icon, Minimize and Maximize buttons) behind.
    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
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Disable Close button

    e.cancel

    does the job just as well Doesn't require API either.
    I don't live here any more.

  5. #5

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Disable Close button

    I would consider it better practice to prevent an illegal action being performed in the first place than allowing it and then telling the user they have done something wrong. If you want to only allow the use of the Close button under certain circumstances or make sure some action occurs when it is used, then the Closing event is a good option. If you want to disallow use of the Close button altogether, as some people seem to want to, then disabling it is a better idea.

    I don't understand why some people seem so hell-bent on differentiating the use of that Close button from other methods of closing a form or app. As far as I'm concerned closing a form is closing a form, and if there is some essential action to perform then do it from the Closing event handler. As some do seem keen to make the distinction, I thought that this would be good to know.
    Last edited by jmcilhinney; Jul 26th, 2005 at 10:01 AM. Reason: Spelling error
    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
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Disable Close button

    I guess the biggest reason is because it is an unexpected event...not supposed to happen...


    - ØØ -

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