Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to remove (not disable) the close button (X) from Window form in C# ?
Please help...
Thanks
dinesh
Posted
Updated 8-Jul-21 5:30am

use the below property

FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
 
Share this answer
 
I personaly know 3 ways this can be done, but it depends alot of you needs of the minimize and maxisize buttons.

the first one is to set the border style to "none" in the properties menu, however this will completely remove all buttons and the "windows header thingy" in the top on the window.

the second method is to set the controlBox property to false. this will remove all buttons but you'll keep the header.

the last one i know is to make your own form with user-controls, but for that i must say you must google you to the result since i dont know much about user-controls, but the first 2 should do the job just fine if you aint too picky :)

Hope this help - Jackie
 
Share this answer
 
Comments
Ajvirk 12-Nov-11 1:48am    
+5 for the second option. And you can find it in the form properties.
On form Load make control box to false

C#
this.ControlBox = false;
 
Share this answer
 
To hide the close button completely without a line of code, set the following:

1. All BorderIcons := False
2. BorderStyle := bsSingle
 
Share this answer
 
Private Const CP_NOCLOSE_BUTTON As Integer = &H200
Private Const WS_SYSMENU As Integer = &H80000
Protected Overrides ReadOnly Property CreateParams As CreateParams
Get
Dim myCp As CreateParams = MyBase.CreateParams
'myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON
myCp.Style = myCp.Style And Not WS_SYSMENU
Return myCp
End Get
End Property
 
Share this answer
 
This worked for me

private const int CP_NOCLOSE_BUTTON = 0x200;
       private const int WS_CAPTION = 0x00C00000;

       // Removes the close button in the caption bar
       protected override CreateParams CreateParams
       {
           get
           {
               CreateParams myCp = base.CreateParams;

               // This disables the close button
               // myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;

               // this appears to completely remove the close button
               myCp.Style &= WS_CAPTION;

               return myCp;
           }
       }
 
Share this answer
 
This worked for me

private const int CP_NOCLOSE_BUTTON = 0x200;
private const int WS_CAPTION = 0x00C00000;

// Removes the close button in the caption bar
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;

// This disables the close button
// myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;

// this appears to completely remove the close button
myCp.Style &= WS_CAPTION;

return myCp;
}
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900