Results 1 to 7 of 7

Thread: Call a Form from MDI Window? [Resolved]

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Question Call a Form from MDI Window? [Resolved]

    How can i call a Form from a MDI Window?

    How can i set a Form as a child of a MDI Window?

    "Form1.Show" works in VB 6.0, now does not work in VB .NET.

    Any solution VB .NET to show a Form?

    Please guide. 10q!
    Last edited by albertlse; Aug 21st, 2003 at 08:05 PM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: Call a Form from MDI Window?

    To show a form do this :

    VB Code:
    1. dim myform as new yourform
    2. myform.show

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    To create new child form just call this little sub .

    VB Code:
    1. Private Sub NewChild()
    2.         Dim fc As New YourChildform()
    3.         fc.MdiParent = Me
    4.         fc.Show()
    5.     End Sub

  4. #4

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Question

    In my case, I try to open Form1 from mdiForm.

    This is how i wrote in mdiForm:

    Private Sub mnuFileNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileNew.Click
    Dim frmNewEntry As frmEntry

    frmNewEntry.Show()
    End Sub

    Is this correct?

    But why the error message below keep on occur?
    "System.NullReferenceException: Object reference not set to an instance of an object."

    Please guide. Thank you.

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by albertlse

    This is how i wrote in mdiForm:

    Private Sub mnuFileNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileNew.Click
    Dim frmNewEntry As frmEntry

    frmNewEntry.Show()
    End Sub
    You need to create new(instaciate) object of frmEntry by using New keyword. You have to read more about OOP in .NET . So your code should look like so :
    VB Code:
    1. Private Sub mnuFileNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileNew.Click
    2. Dim frmNewEntry As New frmEntry
    3.  
    4.     frmNewEntry.Show()
    5. End Sub

  6. #6
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    "System.NullReferenceException: Object reference not set to an instance of an object." is usually an indication that you did not use the "New" keyword to instantiate the object prior trying to use it.

  7. #7

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Smile

    It's working fine now! Thank you!

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