locked
How to disable the close button in VB.net Windows form RRS feed

  • Question

  • HI experts,

    I am facing one issue in my VB.net application. In my application I want to disable the close button in all my windows. I am doing this by following code. But the real issue is while I am minimized and maximized the window the close button is getting enabled to the end user.  How to permanently disable the Close window.

    Public Class CloseButton
            Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal revert As Integer) As Integer
            Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As Integer, ByVal ideEnableItem As Integer, ByVal enable As Integer) As Integer
            Private Const SC_CLOSE As Integer = &HF060
            Private Const MF_BYCOMMAND As Integer = &H0
            Private Const MF_GRAYED As Integer = &H1
            Private Const MF_ENABLED As Integer = &H0
            Private Sub New()
            End Sub

            Public Shared Sub Disable(ByVal form As System.Windows.Forms.Form)

                ' The return value specifies the previous state of the menu item (it is either
                ' MF_ENABLED or MF_GRAYED). 0xFFFFFFFF indicates   that the menu item does not exist.
                Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)
                    Case MF_ENABLED
                    Case MF_GRAYED
                    Case &HFFFFFFFF
                        Throw New Exception("The Close menu item does not exist.")
                    Case Else
                End Select
            End Sub
        End Class

    Private Sub TestForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            CloseButton.Disable(Me)
        End Sub


    Thanks in advance

    Karthick

    Friday, December 12, 2008 3:37 PM

Answers

  • Karthick_PTPL said:

    HI experts,

    I am facing one issue in my VB.net application. In my application I want to disable the close button in all my windows. I am doing this by following code. But the real issue is while I am minimized and maximized the window the close button is getting enabled to the end user.  How to permanently disable the Close window.


    Thanks in advance

    Karthick




    Hi,

    Use.

    Option Strict On 
     
    Public Class Form1  
     
        Private Sub Form1_FormClosing(ByVal sender As ObjectByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing  
     
            e.Cancel = True 
     
        End Sub 
    End Class 
     

    Though I would use this method with another button on the FORM to close the FORM.

    If the button to close the FORM is Button1 then use this idea as otherwise the end-user would need to resort to Task-Manager to close your PROGRAM.>>

    Option Strict On 
     
    Public Class Form1  
     
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click  
     
            End 
     
        End Sub 
     
        Private Sub Form1_FormClosing(ByVal sender As ObjectByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing  
     
            e.Cancel = True 
     
        End Sub 
     
    End Class 
     


    Regards,

    John
    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    Sunday, December 14, 2008 9:57 AM
  • Karthick_PTPL said:

    HI experts,

    I am facing one issue in my VB.net application. In my application I want to disable the close button in all my windows. I am doing this by following code. But the real issue is while I am minimized and maximized the window the close button is getting enabled to the end user.  How to permanently disable the Close window.

    Public Class CloseButton
            Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal revert As Integer) As Integer
            Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As Integer, ByVal ideEnableItem As Integer, ByVal enable As Integer) As Integer
            Private Const SC_CLOSE As Integer = &HF060
            Private Const MF_BYCOMMAND As Integer = &H0
            Private Const MF_GRAYED As Integer = &H1
            Private Const MF_ENABLED As Integer = &H0
            Private Sub New()
            End Sub

            Public Shared Sub Disable(ByVal form As System.Windows.Forms.Form)

                ' The return value specifies the previous state of the menu item (it is either
                ' MF_ENABLED or MF_GRAYED). 0xFFFFFFFF indicates   that the menu item does not exist.
                Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)
                    Case MF_ENABLED
                    Case MF_GRAYED
                    Case &HFFFFFFFF
                        Throw New Exception("The Close menu item does not exist.")
                    Case Else
                End Select
            End Sub
        End Class

    Private Sub TestForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            CloseButton.Disable(Me)
        End Sub


    Thanks in advance

    Karthick



    Hi,

    Your code is very nearly correct. This works!!

    I have moved the Form_Load event to the top of the code. I prefer it that way.

    Otherwise the only other difference is

    Call Disable(Me)

    instead of

    CloseButton.Disable(Me)

    The call to the DISABLE routine is also called from the Resize event otherwise the FORM CLOSE button is ENABLED when the FORM is Maximized.>>

    Option Strict On 
     
    Public Class Form1  
     
        Private Sub TestForm_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
     
            Call Disable(Me)  
     
        End Sub 
     
        Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As IntegerByVal revert As IntegerAs Integer 
        Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As IntegerByVal ideEnableItem As IntegerByVal enable As IntegerAs Integer 
        Private Const SC_CLOSE As Integer = &HF060  
        Private Const MF_BYCOMMAND As Integer = &H0  
        Private Const MF_GRAYED As Integer = &H1  
        Private Const MF_ENABLED As Integer = &H0  
     
        Public Shared Sub Disable(ByVal form As System.Windows.Forms.Form)  
     
            ' The return value specifies the previous state of the menu item (it is either     
            ' MF_ENABLED or MF_GRAYED). 0xFFFFFFFF indicates   that the menu item does not exist.     
            Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)  
                Case MF_ENABLED  
                Case MF_GRAYED  
                Case &HFFFFFFFF  
                    Throw New Exception("The Close menu item does not exist.")  
                Case Else 
            End Select 
        End Sub 
     
        Private Sub Form1_Resize(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Resize  
     
            Call Disable(Me)  
     
        End Sub 
    End Class 
     


    Regards,

    John

    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    Sunday, December 14, 2008 10:07 AM
  • Hi Karthick_PTPL,

    Use this code:

    Public Class CloseButton  
     
        Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As IntegerByVal revert As IntegerAs Integer 
        Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As IntegerByVal ideEnableItem As IntegerByVal enable As IntegerAs Integer 
        Private Const SC_CLOSE As Integer = &HF060  
        Private Const MF_BYCOMMAND As Integer = &H0  
        Private Const MF_GRAYED As Integer = &H1  
        Private Const MF_ENABLED As Integer = &H0  
     
        Public Shared Sub Disable(ByVal form As System.Windows.Forms.Form)  
            Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)  
                Case MF_ENABLED  
                Case MF_GRAYED  
                Case &HFFFFFFFF  
                    Throw New Exception("The Close menu item does not exist.")  
                Case Else 
            End Select 
        End Sub 
     
        Private Sub TestForm_Resize(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Resize  
            CloseButton.Disable(Me)  
        End Sub 
     
        Private Sub TestForm_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            CloseButton.Disable(Me)  
        End Sub 
     
    End Class 
     
     


    Bill
    • Proposed as answer by HrBill32 Friday, December 12, 2008 9:08 PM
    • Marked as answer by Martin Xie - MSFT Wednesday, December 17, 2008 7:13 AM
    • Marked as answer by Martin Xie - MSFT Wednesday, December 17, 2008 7:29 AM
    Friday, December 12, 2008 9:08 PM

All replies

  • I found an article that might point you in the right direction.

    http://www.devasp.net/net/articles/display/307.html

    Hope this helps.

    -Nate

    Friday, December 12, 2008 6:21 PM
  • Also, alternatively, you can set the ControlBox property to False, but this removes minimize and maximize as well. Just depends on what exactly it is you want.
    Friday, December 12, 2008 6:23 PM
  • Look at and search on "CreateParams".  There are posts on these forums describing the procedure.

    Friday, December 12, 2008 6:44 PM
  • Which Close button are you talking about?

    If you create the close then disable it yourself...

    If its the X in the upper right corner you can remove it by settings the Forms ControlBox property to false.


    Friday, December 12, 2008 7:23 PM
  • Hi Karthick_PTPL,

    Use this code:

    Public Class CloseButton  
     
        Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As IntegerByVal revert As IntegerAs Integer 
        Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As IntegerByVal ideEnableItem As IntegerByVal enable As IntegerAs Integer 
        Private Const SC_CLOSE As Integer = &HF060  
        Private Const MF_BYCOMMAND As Integer = &H0  
        Private Const MF_GRAYED As Integer = &H1  
        Private Const MF_ENABLED As Integer = &H0  
     
        Public Shared Sub Disable(ByVal form As System.Windows.Forms.Form)  
            Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)  
                Case MF_ENABLED  
                Case MF_GRAYED  
                Case &HFFFFFFFF  
                    Throw New Exception("The Close menu item does not exist.")  
                Case Else 
            End Select 
        End Sub 
     
        Private Sub TestForm_Resize(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Resize  
            CloseButton.Disable(Me)  
        End Sub 
     
        Private Sub TestForm_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            CloseButton.Disable(Me)  
        End Sub 
     
    End Class 
     
     


    Bill
    • Proposed as answer by HrBill32 Friday, December 12, 2008 9:08 PM
    • Marked as answer by Martin Xie - MSFT Wednesday, December 17, 2008 7:13 AM
    • Marked as answer by Martin Xie - MSFT Wednesday, December 17, 2008 7:29 AM
    Friday, December 12, 2008 9:08 PM
  • That seems like a whole lot of work when you can just set the System.Windows.Form.Button.Enabled property to false in the Form_Load event handler for the form.  Any reason you aren't just doing this, or why the default value for the control isn't Enabled=false?


    -- Jonathan Kehayias (MCITP) | Please mark answers that solve your problem | http://www.sqlclr.net
    Saturday, December 13, 2008 4:17 AM
  • Hi HrBill,

    Thanks for your suggestion, its working fine. If i stuck in some place i will ping you.

    Karthick
    Saturday, December 13, 2008 5:31 AM
  • HI HrBill,


    I am having form called Test1 which contains button( Button1). When I press the button the message box is getting displaying,but at the same time I am accessing the Form Test1. It should not be the case, because before closing the message box the control should not allow to focus the Test1. But in my case the control is allowing to focus the Test1(form) before closing the message box.

    Sample code.
    .
    .
    .
    .
        If myReader.Read() Then

                    MsgBox("Matched record exist.", MsgBoxStyle.Information, "Data Tool")


                Else

                   MsgBox("Matched record does not exist.")

              End If
    .
    .
    .
    .
    In used both the customized and default Message box but I am facing the same issue as mentioned above. 

    Thanks
    Karthick

    Saturday, December 13, 2008 5:09 PM
  • HI Expert,


    I am having form called Test1 which contains button( Button1). When I press the button the message box is getting displaying,but at the same time I am accessing the Form Test1. It should not be the case, because before closing the message box the control should not allow to focus the Test1. But in my case the control is allowing to focus the Test1(form) before closing the message box.

    Sample code.
    .
    .
    .
    .
        If myReader.Read() Then

                    MsgBox("Matched record exist.", MsgBoxStyle.Information, "Data Tool")


                Else

                   MsgBox("Matched record does not exist.")

              End If
    .
    .
    .
    .
    In used both the customized and default Message box but I am facing the same issue as mentioned above. 

    Thanks
    Karthick
    Saturday, December 13, 2008 5:10 PM
  • when you open the messagebox try this syntax

    MessageBox.Show("Matched record exist.", "Data Tool", MessageBoxButtons.OK, MessageBoxIcon.Information)

    Sunday, December 14, 2008 2:36 AM
  • Karthick_PTPL said:

    HI experts,

    I am facing one issue in my VB.net application. In my application I want to disable the close button in all my windows. I am doing this by following code. But the real issue is while I am minimized and maximized the window the close button is getting enabled to the end user.  How to permanently disable the Close window.


    Thanks in advance

    Karthick




    Hi,

    Use.

    Option Strict On 
     
    Public Class Form1  
     
        Private Sub Form1_FormClosing(ByVal sender As ObjectByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing  
     
            e.Cancel = True 
     
        End Sub 
    End Class 
     

    Though I would use this method with another button on the FORM to close the FORM.

    If the button to close the FORM is Button1 then use this idea as otherwise the end-user would need to resort to Task-Manager to close your PROGRAM.>>

    Option Strict On 
     
    Public Class Form1  
     
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click  
     
            End 
     
        End Sub 
     
        Private Sub Form1_FormClosing(ByVal sender As ObjectByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing  
     
            e.Cancel = True 
     
        End Sub 
     
    End Class 
     


    Regards,

    John
    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    Sunday, December 14, 2008 9:57 AM
  • Karthick_PTPL said:

    HI experts,

    I am facing one issue in my VB.net application. In my application I want to disable the close button in all my windows. I am doing this by following code. But the real issue is while I am minimized and maximized the window the close button is getting enabled to the end user.  How to permanently disable the Close window.

    Public Class CloseButton
            Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal revert As Integer) As Integer
            Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As Integer, ByVal ideEnableItem As Integer, ByVal enable As Integer) As Integer
            Private Const SC_CLOSE As Integer = &HF060
            Private Const MF_BYCOMMAND As Integer = &H0
            Private Const MF_GRAYED As Integer = &H1
            Private Const MF_ENABLED As Integer = &H0
            Private Sub New()
            End Sub

            Public Shared Sub Disable(ByVal form As System.Windows.Forms.Form)

                ' The return value specifies the previous state of the menu item (it is either
                ' MF_ENABLED or MF_GRAYED). 0xFFFFFFFF indicates   that the menu item does not exist.
                Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)
                    Case MF_ENABLED
                    Case MF_GRAYED
                    Case &HFFFFFFFF
                        Throw New Exception("The Close menu item does not exist.")
                    Case Else
                End Select
            End Sub
        End Class

    Private Sub TestForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            CloseButton.Disable(Me)
        End Sub


    Thanks in advance

    Karthick



    Hi,

    Your code is very nearly correct. This works!!

    I have moved the Form_Load event to the top of the code. I prefer it that way.

    Otherwise the only other difference is

    Call Disable(Me)

    instead of

    CloseButton.Disable(Me)

    The call to the DISABLE routine is also called from the Resize event otherwise the FORM CLOSE button is ENABLED when the FORM is Maximized.>>

    Option Strict On 
     
    Public Class Form1  
     
        Private Sub TestForm_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
     
            Call Disable(Me)  
     
        End Sub 
     
        Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As IntegerByVal revert As IntegerAs Integer 
        Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As IntegerByVal ideEnableItem As IntegerByVal enable As IntegerAs Integer 
        Private Const SC_CLOSE As Integer = &HF060  
        Private Const MF_BYCOMMAND As Integer = &H0  
        Private Const MF_GRAYED As Integer = &H1  
        Private Const MF_ENABLED As Integer = &H0  
     
        Public Shared Sub Disable(ByVal form As System.Windows.Forms.Form)  
     
            ' The return value specifies the previous state of the menu item (it is either     
            ' MF_ENABLED or MF_GRAYED). 0xFFFFFFFF indicates   that the menu item does not exist.     
            Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)  
                Case MF_ENABLED  
                Case MF_GRAYED  
                Case &HFFFFFFFF  
                    Throw New Exception("The Close menu item does not exist.")  
                Case Else 
            End Select 
        End Sub 
     
        Private Sub Form1_Resize(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Resize  
     
            Call Disable(Me)  
     
        End Sub 
    End Class 
     


    Regards,

    John

    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    Sunday, December 14, 2008 10:07 AM
  • Hi ALL,

    Does anyone know the values to use to DISABLE just the Maximize Button or just the Minimize button please?


    Regards,

    John
    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    Sunday, December 14, 2008 10:17 AM
  • Jonathan Kehayias said:

    That seems like a whole lot of work when you can just set the System.Windows.Form.Button.Enabled property to false in the Form_Load event handler for the form.  Any reason you aren't just doing this, or why the default value for the control isn't Enabled=false?


    -- Jonathan Kehayias (MCITP) | Please mark answers that solve your problem | http://www.sqlclr.net



    Hi Jonathan,
    The OP is disabling the X FORM_Close button on the top right corner of the FORM.

    Try the code in my 2nd post please.


    Regards

    John
    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    Sunday, December 14, 2008 10:23 AM
  • Hi Karthick_PTPL

    I had a similar answer for you here.>>

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/eba7b0a1-4455-4bea-b5ec-f9d5731e1449

    By the way you do not need to post the same question twice, especially in the same forum area.

    Your question(s) will still get noticed.

    To any moderator reading this, you may want to merge this thread with the one I refer to above?


    Regards,

    John


    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    • Edited by John Anthony Oliver Monday, December 15, 2008 7:47 AM Added further text for the attention of a moderator.
    Monday, December 15, 2008 7:39 AM
  • To diable maximum button or minmum button on the toolbar, you can use the following under your Load()

    Me.MaxButton = false
    Me.MinButton = false

    Hope this helps.
    Tuesday, December 16, 2008 2:28 AM
  • masuda0916 said:

    To diable maximum button or minmum button on the toolbar, you can use the following under your Load()

    Me.MaxButton = false
    Me.MinButton = false

    Hope this helps.



    Hi masuda0916,

    Yes of course, I forgot to look for those properties of a FORM.

    Doh!! I must have been tired. My sleep pattern is not regular at the moment.


    Regards,

    John
    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    Tuesday, December 16, 2008 3:42 AM
  • Hi Bill,

    You below suggestion is working fine. but in my case i want the (X) button visibility off (i.e., it should not be visible to user)

    Is it possible....?

    Hi Karthick_PTPL,

    Use this code:

    Public Class CloseButton  
     
        Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As IntegerByVal revert As IntegerAs Integer 
        Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As IntegerByVal ideEnableItem As IntegerByVal enable As IntegerAs Integer 
        Private Const SC_CLOSE As Integer = &HF060  
        Private Const MF_BYCOMMAND As Integer = &H0  
        Private Const MF_GRAYED As Integer = &H1  
        Private Const MF_ENABLED As Integer = &H0  
     
        Public Shared Sub Disable(ByVal form As System.Windows.Forms.Form)  
            Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)  
                Case MF_ENABLED  
                Case MF_GRAYED  
                Case &HFFFFFFFF  
                    Throw New Exception("The Close menu item does not exist.")  
                Case Else 
            End Select 
        End Sub 
     
        Private Sub TestForm_Resize(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Resize  
            CloseButton.Disable(Me)  
        End Sub 
     
        Private Sub TestForm_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            CloseButton.Disable(Me)  
        End Sub 
     
    End Class 
     
     


    Bill


    PBL (Visual Studio 2010 Ultimate)
    Thursday, October 20, 2011 7:29 AM
  • Hi all,

    You can use this code:

        Private Sub TestForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Call Disable(Me)
        End Sub
    
        Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal revert As Integer) As Integer
        Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As Integer, ByVal ideEnableItem As Integer, ByVal enable As Integer) As Integer
    
        Public Shared Sub Disable(ByVal form As System.Windows.Forms.Form)
            Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), &HF060, 1)
                Case &HFFFFFFFF
            End Select
        End Sub
    
        Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
            Call Disable(Me)
        End Sub
    End Class


    • Proposed as answer by isacnoureddine Thursday, August 2, 2012 11:06 AM
    Thursday, August 2, 2012 11:05 AM
  • Hi,

    This works for me:

    Private Const CP_NOCLOSE_BUTTON As Integer = &H200
    	''' <summary>
    	''' Disable the close button only want close to occur via Cancel button
    	''' </summary>
    	''' <value></value>
    	''' <returns></returns>
    	''' <remarks></remarks>
    	Protected Overrides ReadOnly Property CreateParams() As CreateParams
    		Get
    			Dim cp As CreateParams = MyBase.CreateParams
    			cp.ClassStyle = cp.ClassStyle Or CP_NOCLOSE_BUTTON
    			Return cp
    		End Get
    	End Property

    • Proposed as answer by IronRazerz Friday, October 28, 2016 9:57 AM
    Monday, July 15, 2013 12:06 PM
  • No need coding. The easiest best way: 
    Open properties of the form, under Windows Style Disable Control Box by switching it to False
    Thursday, October 27, 2016 10:31 PM
  • No need coding. The easiest best way: 
    Open properties of the form, under Windows Style Disable Control Box by switching it to False

    Then there is no minimize and maximize button which is why some peeps just want to disable the close button. And if the control box is removed I'm fairly certain the system menu (click on the apps icon) removes the minimize, maximize and close menu items.

    La vida loca

    Saturday, October 29, 2016 2:32 AM
  • Very simple solution and it works also for me
    Wednesday, June 26, 2019 9:11 AM