Thread: Form.ShowDialog() strangeness

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445

    Form.ShowDialog() strangeness

    I am writing a program that will help to keep track of maintenance on PCs at the company I work for. An issue I'm running into is that I have a form that I call ShowDialog() on, which in turn creates another form and calls ShowDialog() on that form. when the second form is closed with OK or Cancel, the one that created it closes as well. Is there any way to prevent this behavior?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Simple. Call "Close" instead of whatever you're calling which closes the entire program.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Magos View Post
    Simple. Call "Close" instead of whatever you're calling which closes the entire program.
    it's not closing the entire program. I have the main window, which we'll call 'main' for the purposes of this discussion. we then have form1, upon which I call ShowDialog(). form1 then creates form2, and calls ShowDialog() on that. when I call Close() from form2 it closes form1 and form2, leaving only main. it's like the signals from form2 are getting forwarded to form1 or something.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Why not post the code so we won't have to guess?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    129
    I've had this issue before. You have to be seriously specific about what form you are closing. VERY.

    It's also better to hide first, and make sure the forms only inherit from the base Form, and not from other stuff that they both share.
    He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

    The fool wonders, the wise man asks. - Benjamin Disraeli

    There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    any time I close a form I am working with, I always say this.Close(). is there any more that I need to do, such as setting DialogResult or anything?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strangeness
    By pfs in forum C Programming
    Replies: 16
    Last Post: 09-26-2008, 10:43 PM
  2. Modem Driver Strangeness.
    By civix in forum Tech Board
    Replies: 1
    Last Post: 03-26-2006, 08:02 PM
  3. integer strangeness
    By lostminds in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2002, 01:04 AM