Click here to Skip to main content
15,867,860 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Disable Close Button from Title bar of a Window

Rate me:
Please Sign up or sign in to vote.
4.69/5 (4 votes)
8 Dec 2009CPOL 12.4K   3   2
we can also override the CreateParams Code:[I did not write this code, but i found it a while back.]Visual C# .NET-------------------------------------------------#region "Disable the 'X'"protected override CreateParams CreateParams { get { CreateParams cp =...
we can also override the CreateParams Code:

[I did not write this code, but i found it a while back.]

Visual C# .NET
-------------------------------------------------

#region "Disable the 'X'"
protected override CreateParams CreateParams {
    get {
        CreateParams cp = base.CreateParams;
        const int CS_NOCLOSE = 0x200;
        cp.ClassStyle = cp.ClassStyle | CS_NOCLOSE;
        return cp;
    }
}
#endregion


Visual Basic .NET
-------------------------------------------------

#Region "Disable the 'X'"
    Protected Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            Const CS_NOCLOSE As Integer = &H200
            cp.ClassStyle = cp.ClassStyle Or CS_NOCLOSE
            Return cp
        End Get
    End Property
#End Region

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 1 unable to extend and plug in other o... Pin
Youzelin4-Jul-11 21:22
Youzelin4-Jul-11 21:22 
Reason for my vote of 1
unable to extend and plug in other operations which use WndParams
GeneralYa... but how to enable it back again? Pin
maxxon1517-Apr-11 5:35
maxxon1517-Apr-11 5:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.