Results 1 to 11 of 11

Thread: [RESOLVED] .ShowDialog() causing annoyances

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Resolved [RESOLVED] .ShowDialog() causing annoyances

    I'm making a program and it requires a Form to show that requires an action before the user can go back to the main Form. Of course to do this I am using .ShowDialog(), but unfortunately I have found out that ShowDialog() has some annoying querks.

    Firstly, any time I pressed a button it would exit the entire application. After loads of googling I finally found out that you have to use

    Code:
    Me.DialogResult = None
    At the end of each button click in order to keep the Form from closing.

    But secondly, anything that I do to the Form is saved! So for instance I have a listbox that I populate with some code during the Form's Load Event. Well after I close it, if I bring the Form back up the items in the ListBox quadruples! I don't know why it's times 4 but I know that if I clear the items on each load it stops this. So whenever I use .ShowDialog() stuff is leftover on the form even after I .Close() it.

    While I can find impractical ways around it, such as the Me.DialogResult and resetting all the Forms properties on load, I would like to know if there is anything I can do to prevent those two problems, any work around or other options.

    Also I have tried just plain Show and everything works perfectly, it's just that then the user can switch to the main form with the second window still open, which is why I was using .ShowDialog in the first place.

    code
    At first I had this
    Code:
    QuickLoadForm.ShowDialog()
    Then I looked at the MSDN Library and changed it to this
    Code:
            Dim instance As Form = QuickLoadForm
            Dim returnValue As DialogResult
            returnValue = instance.ShowDialog()
    I still have the problem however and I'm guessing that Modal forms are supposed to behave like that. But saving all the forms settings is really annoying and doesn't make any sense to me so if someone knows how to turn that off I'd appreciate it.

    EDIT: Well I should of finished reading the MSDN Article

    Code:
    Close method is not called by the .NET Framework when the user clicks the close form button of a dialog box or sets the value of the DialogResult property. Instead the form is hidden and can be shown again without creating a new instance of the dialog box. Because a form displayed as a dialog box is not closed, you must call the Dispose method of the form when the form is no longer needed by your application.
    I'm tried it out and putting Me.Dispose() on the Form Close event fixed "save form properties" problem


    However I still would like to know if there is an easy way to set the DialogResult so that you don't have to use:

    Code:
    Me.DialogResult = None
    at the end of every button click. I tried using it on the Form Load but it still exits on any click.
    Last edited by Vectris; May 26th, 2009 at 09:27 PM.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

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