Results 1 to 11 of 11

Thread: [2005] Disable X button

  1. #1

    Thread Starter
    Hyperactive Member leeprice2006's Avatar
    Join Date
    Jul 2006
    Posts
    258

    [2005] Disable X button

    is there a way to disable the X button on a form?
    Hello, Im a complete beginner so I if I ask obvious questions don't laugh. I have had no special training and I thought I'd learn and I thought this is the best place to start.

    I started off using VB 6.0 but when I bought a new computer I decided to upgrade to VB 2005, so its a little bit different to what i'm used to

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Disable X button

    In the Form_Closing routine of the Form you can add this in to disable the X button:
    vb Code:
    1. If e.CloseReason = CloseReason.UserClosing Then
    2.     e.Cancel = True
    3. End If
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3

    Thread Starter
    Hyperactive Member leeprice2006's Avatar
    Join Date
    Jul 2006
    Posts
    258

    Re: [2005] Disable X button

    this code disables all ways of closing the form all I want to disable is the X button and Alt+F4
    Hello, Im a complete beginner so I if I ask obvious questions don't laugh. I have had no special training and I thought I'd learn and I thought this is the best place to start.

    I started off using VB 6.0 but when I bought a new computer I decided to upgrade to VB 2005, so its a little bit different to what i'm used to

  4. #4
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Disable X button

    If I add a button to the form and in its button click event for example I put:

    Application.Exit

    it closes just fine.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  5. #5

    Thread Starter
    Hyperactive Member leeprice2006's Avatar
    Join Date
    Jul 2006
    Posts
    258

    Re: [2005] Disable X button

    i dont want to add exit the application. I want to close a dialog form. so i use Me.Close() and this doesnt close
    Hello, Im a complete beginner so I if I ask obvious questions don't laugh. I have had no special training and I thought I'd learn and I thought this is the best place to start.

    I started off using VB 6.0 but when I bought a new computer I decided to upgrade to VB 2005, so its a little bit different to what i'm used to

  6. #6
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Disable X button

    You might just have to set its visible property to false then instead of calling me.close.

    Then call Application.Exit at the very end to close everything when done.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Disable X button

    You can use an API or two to disable the 'x' close button which also removes the system menu item of Close.

    http://www.vbforums.com/showpost.php...20&postcount=2
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: [2005] Disable X button

    trust me to break it


  9. #9
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Disable X button

    It's not broken, it's just warning that you haven't returned a value from it on expected paths.

    Are you having trouble getting it to work or something?
    Last edited by stimbo; Apr 5th, 2008 at 05:48 AM.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  10. #10
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2005] Disable X button

    You could just set the control box property to false......but then there would be no maximize or minimize buttons.
    If this post helped you, please click the rate button to say thank you! Remember to mark the thread as resolved too.
    Autoclicker, Hide Taskbar, Sounds on internal speaker, Changing Start Button Text (with code)

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Disable X button

    You could do that but then the rest of the controls/buttons will be removed too. If you only want the 'x' close button disabled then that wont work.

    You can have the sub a Sub instead of a Function and that will remove the warning.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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