Click to See Complete Forum and Search --> : how do i disable the cancel button on the top corner of forms in C#?
odejide
March 13th, 2009, 06:39 AM
pls help me
i want to disable the cancel button on the top corner of forms in C#
how do i do that?
NB i am a beginner
dannystommen
March 13th, 2009, 07:22 AM
what exactly do you mean with the 'cancel button on the top corner of forms in C#' ?
MNovy
March 13th, 2009, 07:38 AM
I guess he is talking about "X"
odejide
March 13th, 2009, 07:39 AM
i mean the little red button on the top right corner of every form that usually carries "X" symbol, that terminates a running program.
dannystommen
March 13th, 2009, 09:10 AM
You cannot disable this button, but there a 2 options you can use
1) Change to FormBorderStyle into 'None', but this does not look very nice
2) Use the formClosing event
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
e.Cancel = true;
}
In this case, the 'X' button (close button) will be enabled, but will not work
dlarkin77
March 13th, 2009, 10:50 AM
Check out this link http://blogs.msdn.com/atosah/archive/2007/05/18/disable-close-x-button-in-winforms-using-c.aspx
BigEd781
March 13th, 2009, 12:14 PM
You can most certainly disable that button by setting the 'ControlBox' proerty to false. Much easier than PInvoke or any other type of hack. I should note that you will also lose the maximize and minimize buttons though.
RaleTheBlade
March 13th, 2009, 12:30 PM
I heard of a way you could do it by overriding the OnPaint method of the form but its been so long since Ive seen it. Ive never done it myself, Ive always just set the ControlBox property of the form to false, thats generally the easiest way but like BigEd said, you will lose your maximize and minimize buttons as well.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.