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 do I exit the program from the main form's constructor

How do I exit the program from the main form's constructor

Scheduled Pinned Locked Moved C#
question
4 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.
  • D Offline
    D Offline
    dino2094
    wrote on last edited by
    #1

    In the constructor of my main form, I do some checking. If it doesn't pass the check, I give a MessageBox then I want to quit the program. As I have the code now, I get an ObjectDisposeException. What is the proper way to quit the program? public Form1() { InitializeComponents(); if(.......){ .... .... this.Close(); } }

    L T 2 Replies Last reply
    0
    • D dino2094

      In the constructor of my main form, I do some checking. If it doesn't pass the check, I give a MessageBox then I want to quit the program. As I have the code now, I get an ObjectDisposeException. What is the proper way to quit the program? public Form1() { InitializeComponents(); if(.......){ .... .... this.Close(); } }

      L Offline
      L Offline
      Leslie Sanford
      wrote on last edited by
      #2

      dino2094 wrote:

      In the constructor of my main form, I do some checking. If it doesn't pass the check, I give a MessageBox then I want to quit the program. As I have the code now, I get an ObjectDisposeException. What is the proper way to quit the program?

      Override OnLoad, and do the checking there. I had the same problem and it took me awhile to figure it out.

      D 1 Reply Last reply
      0
      • L Leslie Sanford

        dino2094 wrote:

        In the constructor of my main form, I do some checking. If it doesn't pass the check, I give a MessageBox then I want to quit the program. As I have the code now, I get an ObjectDisposeException. What is the proper way to quit the program?

        Override OnLoad, and do the checking there. I had the same problem and it took me awhile to figure it out.

        D Offline
        D Offline
        dino2094
        wrote on last edited by
        #3

        It worked! THanks

        1 Reply Last reply
        0
        • D dino2094

          In the constructor of my main form, I do some checking. If it doesn't pass the check, I give a MessageBox then I want to quit the program. As I have the code now, I get an ObjectDisposeException. What is the proper way to quit the program? public Form1() { InitializeComponents(); if(.......){ .... .... this.Close(); } }

          T Offline
          T Offline
          Thomas Stockwell
          wrote on last edited by
          #4

          If it is for the main form would it be better to have the exit program logic in the void main() method of the program rather than of the form.

          Regards, Thomas Stockwell 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. Visit my homepage Oracle Studios[^]

          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