Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Disabling Windows Buttons: Minimize,Restore,Close

Disabling Windows Buttons: Minimize,Restore,Close

Scheduled Pinned Locked Moved C#
question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blekk
    wrote on last edited by
    #1

    Hi, I have created a little button on the form called "Close", and when a user clicks it, it displays a messagebox saying "Do you really want to quit?" with an Ok and a Cancel. Then if they click Ok it does : this.Close(); and if not it doesn't do anything. Now, I want to be able to get data from the X (Close button) on the form to display the same text box or disable the X (Close button) so users have to use the close button that I have created. Any way of doing this? Thanks.

    S S 2 Replies Last reply
    0
    • B Blekk

      Hi, I have created a little button on the form called "Close", and when a user clicks it, it displays a messagebox saying "Do you really want to quit?" with an Ok and a Cancel. Then if they click Ok it does : this.Close(); and if not it doesn't do anything. Now, I want to be able to get data from the X (Close button) on the form to display the same text box or disable the X (Close button) so users have to use the close button that I have created. Any way of doing this? Thanks.

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Put all code that show the message box and eventually cancels the closing operation into the event handler for the FormClosing event and inside the button Click event handler simply call the Close method of your form.


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      1 Reply Last reply
      0
      • B Blekk

        Hi, I have created a little button on the form called "Close", and when a user clicks it, it displays a messagebox saying "Do you really want to quit?" with an Ok and a Cancel. Then if they click Ok it does : this.Close(); and if not it doesn't do anything. Now, I want to be able to get data from the X (Close button) on the form to display the same text box or disable the X (Close button) so users have to use the close button that I have created. Any way of doing this? Thanks.

        S Offline
        S Offline
        sharpiesharpie
        wrote on last edited by
        #3

        About the button, instead of the Close function, try using the Application.Exit function, the Close one seems to not work in many occasions. And for the x button, i thought this might be a good think to know myself, and i made some research and this is what i came up with: there's an event in frameworks 1.1 which is called Closing (which later became FormClosing in frameworks 2), so you use the event (this.FormClosing +=...) and in the event you can use: e.Cancel = true; this also stops it from closing with the F4 key, so you can do like so: first, define the event: this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing); and then in the event do something like this: void MyForm_FormClosing(object sender, FormClosingEventArgs e) { DialogResult a = MessageBox.Show("Are you sure you want to close the program?","Cancel",MessageBoxButtons.YesNo); if (a == DialogResult.No) e.Cancel = true; } And as for canceling the minimize and maximize buttons? how about just disabling them? or just use the Form.Resize event. hope it helps. -- modified at 10:35 Sunday 11th February, 2007

        B 2 Replies Last reply
        0
        • S sharpiesharpie

          About the button, instead of the Close function, try using the Application.Exit function, the Close one seems to not work in many occasions. And for the x button, i thought this might be a good think to know myself, and i made some research and this is what i came up with: there's an event in frameworks 1.1 which is called Closing (which later became FormClosing in frameworks 2), so you use the event (this.FormClosing +=...) and in the event you can use: e.Cancel = true; this also stops it from closing with the F4 key, so you can do like so: first, define the event: this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing); and then in the event do something like this: void MyForm_FormClosing(object sender, FormClosingEventArgs e) { DialogResult a = MessageBox.Show("Are you sure you want to close the program?","Cancel",MessageBoxButtons.YesNo); if (a == DialogResult.No) e.Cancel = true; } And as for canceling the minimize and maximize buttons? how about just disabling them? or just use the Form.Resize event. hope it helps. -- modified at 10:35 Sunday 11th February, 2007

          B Offline
          B Offline
          Blekk
          wrote on last edited by
          #4

          Thankyou, that helps a great deal. Thankyou for all the effort you put in to finding out about it also.

          1 Reply Last reply
          0
          • S sharpiesharpie

            About the button, instead of the Close function, try using the Application.Exit function, the Close one seems to not work in many occasions. And for the x button, i thought this might be a good think to know myself, and i made some research and this is what i came up with: there's an event in frameworks 1.1 which is called Closing (which later became FormClosing in frameworks 2), so you use the event (this.FormClosing +=...) and in the event you can use: e.Cancel = true; this also stops it from closing with the F4 key, so you can do like so: first, define the event: this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing); and then in the event do something like this: void MyForm_FormClosing(object sender, FormClosingEventArgs e) { DialogResult a = MessageBox.Show("Are you sure you want to close the program?","Cancel",MessageBoxButtons.YesNo); if (a == DialogResult.No) e.Cancel = true; } And as for canceling the minimize and maximize buttons? how about just disabling them? or just use the Form.Resize event. hope it helps. -- modified at 10:35 Sunday 11th February, 2007

            B Offline
            B Offline
            Blekk
            wrote on last edited by
            #5

            I just tried it out, it is amazing, thankyou very much. Except I don't understand the:

            this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing);

            VC# EE just gave me a load of errors on that, and I don't quite know what it's doing anyway. Well, thanks for the great help.

            S 1 Reply Last reply
            0
            • B Blekk

              I just tried it out, it is amazing, thankyou very much. Except I don't understand the:

              this.FormClosing += new FormClosingEventHandler(MyForm_FormClosing);

              VC# EE just gave me a load of errors on that, and I don't quite know what it's doing anyway. Well, thanks for the great help.

              S Offline
              S Offline
              sharpiesharpie
              wrote on last edited by
              #6

              Can you please say what the errors are?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups