Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide Close Button 1

Status
Not open for further replies.

LonnieJohnson

Programmer
Apr 16, 2001
2,628
US
Is there a way to hide "just" the close button on a form? I still want the Minimize and Maximize buttons to show.

I see properties for the min and max. I also see the "control box" property. When I set the control box property to False all the other buttons disappear too.

Any help is appreciated.



ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
This doesn't "hide" the X, but disables it. This is from VB6, but I've used it in 2003.

Code:
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Const MF_BYPOSITION = &H400&
Const MF_REMOVE = &H1000&
Private Sub Form_Load()
    Dim hSysMenu As Long, nCnt As Long
    
    hSysMenu = GetSystemMenu(Me.hwnd, False)

    If hSysMenu Then
        
        nCnt = GetMenuItemCount(hSysMenu)
        If nCnt Then
            RemoveMenu hSysMenu, nCnt - 1, MF_BYPOSITION Or MF_REMOVE
            RemoveMenu hSysMenu, nCnt - 2, MF_BYPOSITION Or MF_REMOVE 
            DrawMenuBar Me.hwnd
            
        End If
    End If
End Sub

IHTH

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Thanks a lot for the quick response.

I am using vs2008.

It does not like hwnd

What is that?

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Me.Handle

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
I also don't know how to hide the close button but here's another option for disabling it:
Code:
    Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
        Get
            Dim params As CreateParams = MyBase.CreateParams
            params.ClassStyle = params.ClassStyle Or &H200 'CS_NOCLOSE
            Return params
        End Get
    End Property
 
Sorry Soren, I could never get that to work.

Thanks DaveInIowa, That did it.


ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top