How to disable Close button on title bar in VB.net

By Allen Stoner

If you want to disable the 'X' for the Window close in a VB.NET you need to add some special code to the form. It is not quite as easy as using a property like the minimize and maximize buttons. Add the following code as a property to your form and it will disable the close button in the Windows bar.

  Protected Overrides ReadOnly Property CreateParams() As CreateParams
    Get
      Dim cp As CreateParams = MyBase.CreateParams
      Const CS_DBLCLKS As Int32 = &H8
      Const CS_NOCLOSE As Int32 = &H200
      cp.ClassStyle = CS_DBLCLKS Or CS_NOCLOSE
      Return cp
    End Get
  End Property

How to disable Close button on title bar in VB.net  (2682 Views)