Apr 7th, 2005, 11:54 AM
#1
Thread Starter
Member
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.
Apr 7th, 2005, 11:59 AM
#2
Re: Disable "close window option"
VB Code:
'In a module
'Call from any form, passing the Form object
Option Explicit On
Private Const MF_DISABLED = &H2&
Private Const MF_BYPOSITION = &H400&
Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
Public Function DisableX(ByRef oForm As System.Windows.Forms.Form)
'<VB/OUTLOOK GURU 11/09/2004 - REMOVES FORM SYSTEM MENU ITEMS BY POSITIONS>
Dim hMenu As Int32
Dim nCount As Integer
hMenu = GetSystemMenu(oForm.Handle.ToInt32, 0)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
Call DrawMenuBar(oForm.Handle.ToInt32)
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Apr 7th, 2005, 12:15 PM
#3
PowerPoster
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.
Apr 7th, 2005, 12:20 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Apr 7th, 2005, 06:43 PM
#5
PowerPoster
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.
Apr 7th, 2005, 07:35 PM
#6
Re: Disable "close window option"
Grey huh,
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Apr 7th, 2005, 09:17 PM
#7
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
Apr 11th, 2005, 09:44 AM
#8
Thread Starter
Member
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:
Module mdlMain
Public optionInterface As New frmOptions
Public insertNewmember As New frmInsertmember
Option Explicit On
Private Const MF_DISABLED = &H2&
Private Const MF_BYPOSITION = &H400&
Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
Public Function DisableX(ByRef oForm As System.Windows.Forms.Form)
'<VB/OUTLOOK GURU 11/09/2004 - REMOVES FORM SYSTEM MENU ITEMS BY POSITIONS>
Dim hMenu As Int32
Dim nCount As Integer
hMenu = GetSystemMenu(oForm.Handle.ToInt32, 0)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
Call DrawMenuBar(oForm.Handle.ToInt32)
End Function
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.
Apr 11th, 2005, 11:21 AM
#9
Re: Disable "close window option"
It should go like this...
VB Code:
Option Explicit On
Module mdlMain
Public optionInterface As New frmOptions
Public insertNewmember As New frmInsertmember
Private Const MF_DISABLED = &H2&
Private Const MF_BYPOSITION = &H400&
Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
Public Function DisableX(ByRef oForm As System.Windows.Forms.Form)
'<VB/OUTLOOK GURU 11/09/2004 - REMOVES FORM SYSTEM MENU ITEMS BY POSITIONS>
Dim hMenu As Int32
Dim nCount As Integer
hMenu = GetSystemMenu(oForm.Handle.ToInt32, 0)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
Call DrawMenuBar(oForm.Handle.ToInt32)
End Function
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Apr 12th, 2005, 11:34 AM
#10
Thread Starter
Member
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.
Apr 12th, 2005, 11:43 AM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Apr 12th, 2005, 11:50 AM
#12
Thread Starter
Member
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
Apr 12th, 2005, 12:06 PM
#13
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:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call DisableX(Me)
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Apr 12th, 2005, 12:37 PM
#14
Thread Starter
Member
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.
Apr 12th, 2005, 12:47 PM
#15
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Apr 12th, 2005, 01:01 PM
#16
Thread Starter
Member
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.
Apr 12th, 2005, 01:05 PM
#17
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Apr 12th, 2005, 01:18 PM
#18
Thread Starter
Member
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?
Apr 12th, 2005, 01:45 PM
#19
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Forum Rules
Click Here to Expand Forum to Full Width