Results 1 to 12 of 12

Thread: [RESOLVED] [2005] Form Show and Showdialog

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Resolved [RESOLVED] [2005] Form Show and Showdialog

    hi im running this code to load a form and call a public method inside it:

    vb Code:
    1. [B] newForm.Show()[/B]
    2.         Call newForm.editToolStripButton_Click(sender, e)



    but when i use form SHOWDIALOG method it doesnt execute
    Call newForm.editToolStripButton_Click(sender, e)

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] Form Show and Showdialog

    ShowDialog is for external files, not internal forms.

  3. #3
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: [2005] Form Show and Showdialog

    I think you're slightly confused Hack. At least, I can't understand what you are trying to say.

    jlbantang, when you call a form's ShowDialog() method, your code will not continue to execute until the form that you have shown as a dialog is closed. Here is a quick test you can use to show the concept:

    Code:
    Private Sub btnShowDialog_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs _
    )  Handles btnShowDialog.Click
        Using frm As New newForm()
            frm.ShowDialog()
            MessageBox.Show("You have reached this line of code.")
        End Using
    End Sub
    
    Private Sub btnShowRegular_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs _
    )  Handles btnShowRegular.Click
        Using frm As New newForm()
            frm.Show()
            MessageBox.Show("You have reached this line of code.")
        End Using
    End Sub
    You will notice that in the first instance, the message box only pops up when you close the newForm, whereas in the second instance, it pops up immediately.

    You are having a problem because after you use the ShowDialog method, your code does not execute the

    Code:
    Call newForm.editToolStripButton_Click(sender, e)
    until the form is closed, at which point it will fail because there is no longer a form.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: [2005] Form Show and Showdialog

    Quote Originally Posted by Hack
    ShowDialog is for external files, not internal forms.
    a bit confuse tho. I believed SHOWDIALOG is the same as showing a MODAL FORM in VB6. please correct me if im wrong.

    thnx

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Form Show and Showdialog

    Yes as Max explained, ShowDialog will block the calling thread until the form shown by the ShowDialog call is closed.

    I should also point out that it is considered bad practise to call eventhandlers directly, you should avoid that.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: [2005] Form Show and Showdialog

    Code that will be called from multiple locations should be wrapped in its own method.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: [2005] Form Show and Showdialog

    thnx. so i wrapped the codes in its own method and still nothing seems to work. what would you suggest experts?

  8. #8
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Form Show and Showdialog

    what does not seem to work and how are you trying to do it?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  9. #9
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: [2005] Form Show and Showdialog

    Well things are wrong with calling into a sub that listens to a UI elements events. You are simulating that the relevant object sent the message. Objects are supposed to tell the outside world that something happened to the object, not the outside world telling the rest of the program that an object raised an event when it didn't. You can do it, but your screwing with the way OOP was meant to operate.

    What to do?
    Just make another sub that contains the code you want to execute and call it instead.

  10. #10
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Form Show and Showdialog

    you don't need to call the form's
    vb Code:
    1. editToolStripButton_Click(sender, e) sub
    . if you do than you need to provide the event args for the click and that is what i don't see you doing. Instead call the button's performClick method.
    vb Code:
    1. newForm.Show()
    2. newForm.editToolStripButton.PerformClick()

  11. #11
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: [2005] Form Show and Showdialog

    Even then the code is a little screwball because you are using the sub both to catch events from within an object, and for external use.
    That sort of muddies the water of the purpose of event handlers.

    And before you say it...
    Remember "Goto"

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: [2005] Form Show and Showdialog

    i supposed to used SHOWDIALOG but since the required step wont allow me to perform a method local to the external form i will use SHOW method instead and that fix all issues.

    tnx.

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