Results 1 to 19 of 19

Thread: Disable "close window option"

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    35

    Disable "close window option"

    How to disable the close window ("X") on the right top corner of a form in VB.NET.

    I would like to keep minimise window and maximise window enable though.

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

    Re: Disable "close window option"

    VB Code:
    1. 'In a module
    2.     'Call from any form, passing the Form object
    3.     Option Explicit On
    4.  
    5.     Private Const MF_DISABLED = &H2&
    6.     Private Const MF_BYPOSITION = &H400&
    7.  
    8.     Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
    9.     Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
    10.     Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
    11.     Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
    12.  
    13.     Public Function DisableX(ByRef oForm As System.Windows.Forms.Form)
    14.         '<VB/OUTLOOK GURU 11/09/2004 - REMOVES FORM SYSTEM MENU ITEMS BY POSITIONS>
    15.         Dim hMenu As Int32
    16.         Dim nCount As Integer
    17.         hMenu = GetSystemMenu(oForm.Handle.ToInt32, 0)
    18.         nCount = GetMenuItemCount(hMenu)
    19.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
    20.         nCount = GetMenuItemCount(hMenu)
    21.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
    22.         Call DrawMenuBar(oForm.Handle.ToInt32)
    23.     End Function
    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

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Disable "close window option"

    Hi,

    You could put
    If bCheck = False then e.Cancel = True


    in the closing event of the form. Then when you come to the point in your code wher you want the form to close, set bCheck to true. (bCheck must have form scope of course)
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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

    Re: Disable "close window option"

    True, but I like the greyed out disabled look and feel of removing the close option from the system menu.
    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

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Disable "close window option"

    By the time I'd written all that code it would be ME that had the "Greyed out look"
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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

    Re: Disable "close window option"

    Grey huh,
    VB Code:
    1. 'In Form1
    2. DisableX(Me)
    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

  7. #7
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Disable "close window option"

    damn...posted in the wrong thread....good beer tho
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    35

    Re: Disable "close window option"

    Hello RobDog888,

    I used the code that you provided in my module where I have some more codes for different forms. So my module looks like as foloows now:

    VB Code:
    1. Module mdlMain
    2.     Public optionInterface As New frmOptions
    3.     Public insertNewmember As New frmInsertmember
    4.  
    5.     Option Explicit On
    6.  
    7.     Private Const MF_DISABLED = &H2&
    8.     Private Const MF_BYPOSITION = &H400&
    9.  
    10.     Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
    11.     Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
    12.     Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
    13.     Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
    14.  
    15.     Public Function DisableX(ByRef oForm As System.Windows.Forms.Form)
    16.         '<VB/OUTLOOK GURU 11/09/2004 - REMOVES FORM SYSTEM MENU ITEMS BY POSITIONS>
    17.         Dim hMenu As Int32
    18.         Dim nCount As Integer
    19.         hMenu = GetSystemMenu(oForm.Handle.ToInt32, 0)
    20.         nCount = GetMenuItemCount(hMenu)
    21.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
    22.         nCount = GetMenuItemCount(hMenu)
    23.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
    24.         Call DrawMenuBar(oForm.Handle.ToInt32)
    25.     End Function
    26. End Module



    VB.NET does not like "Option Explicit On" so I commented it out and run the code. I could not achive the goal.

    I am new in VB.NET so please bear with me and let me know how to handle this situation. Thank you.

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

    Re: Disable "close window option"

    It should go like this...
    VB Code:
    1. Option Explicit On
    2.  
    3. Module mdlMain
    4.     Public optionInterface As New frmOptions
    5.     Public insertNewmember As New frmInsertmember
    6.  
    7.     Private Const MF_DISABLED = &H2&
    8.     Private Const MF_BYPOSITION = &H400&
    9.  
    10.     Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
    11.     Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
    12.     Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
    13.     Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
    14.  
    15.     Public Function DisableX(ByRef oForm As System.Windows.Forms.Form)
    16.         '<VB/OUTLOOK GURU 11/09/2004 - REMOVES FORM SYSTEM MENU ITEMS BY POSITIONS>
    17.         Dim hMenu As Int32
    18.         Dim nCount As Integer
    19.         hMenu = GetSystemMenu(oForm.Handle.ToInt32, 0)
    20.         nCount = GetMenuItemCount(hMenu)
    21.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
    22.         nCount = GetMenuItemCount(hMenu)
    23.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
    24.         Call DrawMenuBar(oForm.Handle.ToInt32)
    25.     End Function
    26. End Module
    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

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    35

    Re: Disable "close window option"

    Hello RobDog888,

    I tried the new version of this code you provided. Now when I run the program the close window ('X') is still visible on the frames ( in my case I have 3 frames so far) ie. Login Frame, User Option Frame, New Member Frame. When I click the ('X'), it closed the frame. Thus I cannot achieve my goal.

    Any suggestion. Thank you.

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

    Re: Disable "close window option"

    I think you mean Form not frame

    Can you post your code that calls the function? Are you using MDI forms?
    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

  12. #12

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    35

    Re: Disable "close window option"

    Sorry that's my bad. I meant form instead of frame.

    What is MDI form?

    I attched the whole project so that you can understand better. Thank you.
    Attached Files Attached Files

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

    Re: Disable "close window option"

    Fixed. You didnt make any calls to disable the x. I changed the folder name to add at the end "_Fixed" so
    you can compare projects.

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.     Call DisableX(Me)
    3. End Sub
    I placed this in all your form load events so it wil disable the x before it loads.
    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

  14. #14

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    35

    Thumbs up Re: Disable "close window option"

    Thank you very much RobDog888. I acieved my gaol this time.

    I am looking for some suggestions about my project. As you have seen the skeleton of my project. I am planning to use this project to store member information and at the same time retrieving the data from the database and updating.

    I am wondering whether I can use MS access on the back ground to store the date or just simple text file.

    If you have any other suggestion, you are more than welcome to inform me. Thank you very much.

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

    Re: Disable "close window option"

    It probably would be best to use Access to store the information. As I usually see that we an app
    is deployed and used in the field, they usually are always wanting more.

    I didnt take too much time going over it but you may also want to think about how the first user account
    will be created so they can log in to create others.
    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

  16. #16

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    35

    Re: Disable "close window option"

    I am not worried about login for the first user or so on since my main concern is store the member information and manupolate those information when necessary.

    How do I link VB.NET and MS Access?

    Thank you.

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

    Re: Disable "close window option"

    You need to use the OleDbDataAdapter and OleDbConnection Objects in the Data toolbox.
    Then when your setup you can use the DataSet or DataView.
    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

  18. #18

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    35

    Re: Disable "close window option"

    Thank you very much. Please bear with since I am very much new with this terms. Could you please le me know about the foloowoing inquires?

    How to use the OleDbDataAdapter and OleDbConnection Objects in the Data toolbox?

    How to use the DataSet or DataView?

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

    Re: Disable "close window option"

    I dont have a whole lot of experience useing them yet, but I think you would get a better response if you
    create a new thread on this new issue

    I will try to continue in there.
    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