Need to get rid of X on Screen

Is there a way i can hide the X on the top left hand corner of my form. I found in the form properties to hide minimise and maximise but i also need to get rid of the close mark X


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Set the ControlBox property to FALSE.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
.only thing is that this gets rid of your icon too.

If you don't want that,

(thanks to Dalin)


Option Explicit

Public Const MF_BYPOSITION = &H400
Public Const MF_REMOVE = &H1000

Public Declare Function DrawMenuBar Lib "user32" _
      (ByVal hwnd As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" _
      (ByVal hMenu As Long) As Long
Public Declare Function GetSystemMenu Lib "user32" _
      (ByVal hwnd As Long, _
       ByVal bRevert As Long) As Long
Public Declare Function RemoveMenu Lib "user32" _
      (ByVal hMenu As Long, _
       ByVal nPosition As Long, _
       ByVal wFlags As Long) As Long'--end block--'

 Form Code
To test, add the following into a command button. Shown here is the code called from the form's Load sub:

Option Explicit

Private Sub Form_Load()

   Dim hMenu As Long
   Dim menuItemCount As Long

  'Obtain the handle to the form's system menu
   hMenu = GetSystemMenu(Me.hwnd, 0)
   If hMenu Then
     'Obtain the number of items in the menu
      menuItemCount = GetMenuItemCount(hMenu)
     'Remove the system menu Close menu item.
     'The menu item is 0-based, so the last
     'item on the menu is menuItemCount - 1
      Call RemoveMenu(hMenu, menuItemCount - 1, _
                      MF_REMOVE Or MF_BYPOSITION)
     'Remove the system menu separator line
      Call RemoveMenu(hMenu, menuItemCount - 2, _
                      MF_REMOVE Or MF_BYPOSITION)
     'Force a redraw of the menu. This
     'refreshes the titlebar, dimming the X
      Call DrawMenuBar(Me.hwnd)

   End If
End Sub
There are a few problems with Caraf Q's code.
It doesn't work with MDI Forms and there are it messes up other menu items.
(For example Move doesn't work)

This code works for me.

Private Declare Function GetSystemMenu _
  Lib "user32" _
  (ByVal hwnd As Long, _
   ByVal bRevert As Long) _
  As Long

Private Declare Function ModifyMenu _
  Lib "user32" _
  Alias "ModifyMenuA" _
  (ByVal hMenu As Long, _
   ByVal nPosition As Long, _
   ByVal wFlags As Long, _
   ByVal wIDNewItem As Long, _
   ByVal lpString As Any) _
  As Long

Private Declare Function GetMenuItemID _
  Lib "user32" _
  (ByVal hMenu As Long, _
   ByVal nPos As Long) _
  As Long

Private Const MF_BYCOMMAND = &H0&
Private Const MF_BYPOSITION = &H400&
Private Const MF_GRAYED = &H1&

Public Sub DisableCloseMenu(frmIn As Form)

  Dim lngResult As Long
  Dim lnghMenu As Long
  Dim lnghItem As Long

  ' get handle to form's system menu
  lnghMenu = GetSystemMenu(frmIn.hwnd, 0)
  ' get handle to the 6th item (Close)
  lnghItem = GetMenuItemID(lnghMenu, 6)
  ' gray out this item
  lngResult = ModifyMenu( _
    lnghMenu, _
    lnghItem, _
    -10, _
End Sub

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Thanks chengman, it's always good to get improvements on one's code.
CraigLazarAuthor Commented:
Thanx allot for the help from everyone
MCrider had it perfect

thanx again

Thanks for the points! Glad I could help!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.