CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2008
    Posts
    13

    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

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    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#' ?

  3. #3
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    210

    Re: how do i disable the cancel button on the top corner of forms in C#?

    I guess he is talking about "X"

  4. #4
    Join Date
    Mar 2008
    Posts
    13

    Post 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.

  5. #5
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    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

  6. #6
    Join Date
    Oct 2004
    Posts
    206

    Re: how do i disable the cancel button on the top corner of forms in C#?


  7. #7
    Join Date
    Jun 2008
    Posts
    2,477

    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.

  8. #8
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    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.
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured