How to hide only the Close (x) button?
You can't hide it, but you can disable it by overriding the CreateParams property of the form.
private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON ;
return myCp;
}
}
Source: http://www.codeproject.com/KB/cs/DisableClose.aspx
How to disable (or hide) the close (x) button on a JFrame?
If I understand it correctly, this bug report indicates that this is currently not possible.
Can I disable the 'close' button of a form using C#?
You handle the Closing event (and not the Closed event) of the Form.
And then you use e.CloseReason to decide if you really want to block it (UserClose) or not (TaskManager Close).
Also, there is small example Disabling Close Button on Forms on codeproject.
VB.NET Disable/Hide x button but WITHOUT disabling closing altogether
In the properties for the form, set the ControlBox
property to False
. Then, in the code, when you want to close the form, just call the form's Close
method.
However, doing that will not stop the user from closing the window via standard OS methods (e.g. via the button on the task bar, via ALT+F4). In order to stop that, you would need to cancel the closing of the form in its FormClosing
event. For instance:
Public Class Form1
Private _closeAllowed As Boolean = False
Private Sub Form1_Click(sender As Object, e As EventArgs) Handles Me.Click
_closeAllowed = True
Close()
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
If Not _closeAllowed Then
e.Cancel = True
End If
End Sub
End Class
However, even that won't stop the application from being terminated. For more thorough solutions, you may want to do some searches on best-practices for developing kiosk applications for Windows.
Hide the close X button in Fancybox
If you take a look at the documentation at http://fancybox.net/api it cites an option of showCloseButton
that should do the trick.
From the site:
showCloseButton - Option to show/hide close button
Is it possible to disable the close button while still being able to close from elsewhere?
This is a simple boolean example:
bool ExitApplication = false;
private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
{
switch(ExitApplication)
{
case false:
this.Hide();
e.Cancel = true;
break;
case true:
break;
}
}
So when you want to close your application just set ExitApplication to true.
Related Topics
System.Speech in Mono on Linux
How to Print the Current Stack Trace in .Net Without Any Exception
Is Ruby's Code Block Same as C#'s Lambda Expression
Catching "Maximum Request Length Exceeded"
How to Build a JSON Object to Send to an Ajax Webservice
An Object Reference Is Required to Access Non-Static Member
How to Submit Http Form Using C#
How to Get the Current Line Number
Why Firefox Requires Geckodriver
Adding Your Own HTMLhelper in ASP.NET MVC 3
How Does the Ternary Operator Work
How to Populate/Instantiate a C# Array with a Single Value
Resharper "Cannot Resolve Symbol" Even When Project Builds
Parsing HTML Page with HTMLagilitypack
Creating a Zip Archive in Memory Using System.Io.Compression