how do i disable the cancel button on the top corner of forms in C#?
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
Re: how do i disable the cancel button on the top corner of forms in C#?
what exactly do you mean with the 'cancel button on the top corner of forms in C#' ?
Re: how do i disable the cancel button on the top corner of forms in C#?
I guess he is talking about "X"
Re: how do i disable the cancel button on the top corner of forms in C#?
i mean the little red button on the top right corner of every form that usually carries "X" symbol, that terminates a running program.
Re: how do i disable the cancel button on the top corner of forms in C#?
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
Code:
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
Re: how do i disable the cancel button on the top corner of forms in C#?
Re: how do i disable the cancel button on the top corner of forms in C#?
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.
Re: how do i disable the cancel button on the top corner of forms in C#?
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.