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. How not to close the window

How not to close the window

Scheduled Pinned Locked Moved C#
questionlearning
4 Posts 4 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.
  • S Offline
    S Offline
    Silvyster
    wrote on last edited by
    #1

    I'm trying to set my program in a way that before the program or I mean the form is to be closed, the program checks whether a text box has a value. So what I did is to make use of the closing event of the form... ok so when the form is closing, the program checks if there is a value on the text box and if empty the program asks the user through a dialog box like "You left that #)($*#$ blank.". When i run the program, the message box pops out so now the next thing to do is to stop the closing of the form if the textbox doesn't have any value.. is there a way to do that? well of course there are other alternatives for validation but on the FORM i'm dependent on the CANCEL (the x button on the upper right) for the closing of the form and nothing else.

    A A D 3 Replies Last reply
    0
    • S Silvyster

      I'm trying to set my program in a way that before the program or I mean the form is to be closed, the program checks whether a text box has a value. So what I did is to make use of the closing event of the form... ok so when the form is closing, the program checks if there is a value on the text box and if empty the program asks the user through a dialog box like "You left that #)($*#$ blank.". When i run the program, the message box pops out so now the next thing to do is to stop the closing of the form if the textbox doesn't have any value.. is there a way to do that? well of course there are other alternatives for validation but on the FORM i'm dependent on the CANCEL (the x button on the upper right) for the closing of the form and nothing else.

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      In the closing event if you set e.Cancel = true; then the form will not close.

      My current favourite word is: Nipple!

      -SK Genius

      Game Programming articles start -here[^]-

      1 Reply Last reply
      0
      • S Silvyster

        I'm trying to set my program in a way that before the program or I mean the form is to be closed, the program checks whether a text box has a value. So what I did is to make use of the closing event of the form... ok so when the form is closing, the program checks if there is a value on the text box and if empty the program asks the user through a dialog box like "You left that #)($*#$ blank.". When i run the program, the message box pops out so now the next thing to do is to stop the closing of the form if the textbox doesn't have any value.. is there a way to do that? well of course there are other alternatives for validation but on the FORM i'm dependent on the CANCEL (the x button on the upper right) for the closing of the form and nothing else.

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        Just Do This !!! private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (textBox1.Text == "") { MessageBox.Show("Please Fill Details"); e.Cancel = true; } else { MessageBox.Show("Thanks You !!!"); } }

        cheers, Abhijit Read My Latest Article : IIS 7.0 and Deploying Asp.Net WebSites on IIS 7.0

        1 Reply Last reply
        0
        • S Silvyster

          I'm trying to set my program in a way that before the program or I mean the form is to be closed, the program checks whether a text box has a value. So what I did is to make use of the closing event of the form... ok so when the form is closing, the program checks if there is a value on the text box and if empty the program asks the user through a dialog box like "You left that #)($*#$ blank.". When i run the program, the message box pops out so now the next thing to do is to stop the closing of the form if the textbox doesn't have any value.. is there a way to do that? well of course there are other alternatives for validation but on the FORM i'm dependent on the CANCEL (the x button on the upper right) for the closing of the form and nothing else.

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          Check out the ErrorProvider[^] class/component.

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Expect everything to be hard and then enjoy the things that come easy. (code-frog)

          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