Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

This is what i have:

 

first i have a main form, and this is the only code in it:

 

    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim frm1 As New Form1 
       frm1.MdiParent = Me
       frm1.Show()
   End Sub

 

That opens up form1 to be the mdichild of form 'Main'.

 

In form 1 i have this code:

 

        Dim chatD As New ChatForm
       chatD.MdiParent = frmMain
       chatD.Text = "Chat"
       chatD.Show()

 

The only problem is that the above code doesn't open it up as an mdiChild of form 'Main'. How could i make form1 open up chatform as an mdiChild of form 'Main'?

 

Thanks in advanced! :)

Posted

        Dim chatD As New ChatForm
       chatD.MdiParent = frmMain
[/quote]

Maybe the frmMain reference isnt working properly. I dont know how VB.NET handles references to forms using the class name (last time VB for me is VB 6 a couple of years back ;) ). frmMain is the form name, not the name of a variable containing the form. It could be that using this construction, VB creates a new frmMain internally, so the chatD.MdiParent refers to an object that is a second instance of the frmMain.

To work around this you would have to make sure you give the chatD form the same reference you use. That shouldnt be to difficult, I think the following would do that trick.
[code]
chatD.MdiParent = me.MdiParent

That would guarantee you reference to the correct form.

Nothing is as illusive as 'the last bug'.
Posted (edited)
Main is the MDI PArent - correct?

Form1 is a child of the Main form - also correct?

ChatForm is another child of the Main form - correct?

 

yes that is correct.

 

Maybe the frmMain reference isnt working properly. I dont know how VB.NET handles references to forms using the class name (last time VB for me is VB 6 a couple of years back ;) ). frmMain is the form name, not the name of a variable containing the form. It could be that using this construction, VB creates a new frmMain internally, so the chatD.MdiParent refers to an object that is a second instance of the frmMain.

 

To work around this you would have to make sure you give the chatD form the same reference you use. That shouldnt be to difficult, I think the following would do that trick.

chatD.MdiParent = me.MdiParent

That would guarantee you reference to the correct form.

 

edit: ah... now i get what your saying. (it took a while for it to click.) Thanks i'll see if that works :)

Edited by decrypt

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...