Question how to display child forms using menustip in MDI Parent form....??

leroy1260

Member
Joined
Apr 4, 2011
Messages
8
Programming Experience
Beginner
Screenshot.jpg


When I click on Borrow Book(s) from Transaction menu it should open frmborrow.vb
Also to it should do the same to rest of the menu(s)......

What should i write in the click event for Borrow Books from Menustrip menu
 
Last edited:
You set the MdiParent property of the desired form to the parent form, then you call Show on the child form. That's all there is to it. You should probably add a call to the Activate method as well, to focus the form if it's already showing.
 
@jmcilhinney

Now I'm able to display form after clicking on Menu Item from Menu strip ....but there is one small change I would like to make ......I'm not able to get get it ....i.e.
After I click on the menu Item from MenutoolStrip the desired form Opens but it Opens in new window, I want it to open in the Parent form itself ....not in a new window ..
This applies to rest of the items in Menutoolstrip....here's an image of it......hope it helps ......

screenshot1_1.jpg




http://www.vbdotnetforums.com/members/jmcilhinney.html
 
If you've done what I said then it would be working. If it's not working then you haven't done what I said. As you haven't shown what you've done, I can't tell what you've done wrong.
 
Child forms not getting minimized along with the parent forms....

I am able to open all child forms corresponding to the click event in the MenuToolStrip ...all in the Parent form
Now the problem is that I cannot minimize child forms when I minimize Parent form..I want child forms also to minimize along with the Parent form..
Also are child forms still not attached to the parent Form is also my question here.....
 
I repeat what I posted previously:
If you've done what I said then it would be working. If it's not working then you haven't done what I said. As you haven't shown what you've done, I can't tell what you've done wrong.
The hint was that you need to post your code so we can see what's wrong with it.
 
I am able to open all child forms corresponding to the click event in the MenuToolStrip ...all in the Parent form
Now the problem is that I cannot minimize child forms when I minimize Parent form..I want child forms also to minimize along with the Parent form..
Also are child forms still not attached to the parent Form is also my question here.....

Here is the code I use on my MDI form to open child forms.

VB.NET:
    Private Sub CurrentMaint_TSMI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CurrentMaint_TSMI.Click
        Dim mdiChild As frmTaskWork = frmTaskWork.Instance() 
        
        With mdiChild
            .MdiParent = Me 'setting the Mdi form as parent of the mdichild variable.
            .Show() 'showing the mdichild form
            .Focus() 'giving focus to the mdichild form
        End With
    End Sub

On my child form I use these two bits of code

VB.NET:
Public Class frmTaskWork
    Private Shared formInstance As frmTaskWork
  
    Public Shared ReadOnly Property Instance() As frmTaskWork
        'checks to see if the form is open already and opens
        'the for if it hasn't already been open.
        Get
            If formInstance Is Nothing Then
                formInstance = New frmTaskWork
            End If
            Return formInstance
        End Get
    End Property

 Private Sub frmTaskWork_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        formInstance = Nothing 'set variable to nothing
    End Sub
end Class

What I am doing with these bits of code is setting the mdiparent of my child form and using the forminstance property to on my child form to only allow one instance of that form to be open at any one time. I'm also setting the forminstance property to nothing when the form is closing this way you can open the form again if necessary.

I hope that helps you with your problem.

-Fred
 
VB.Net includes default form instances, so you don't need to write any code for that, just reference the form by name:
VB.NET:
frmTaskWork.MdiParent = Me
frmTaskWork.Show()
frmTaskWork.Activate()
 
Back
Top