How to add a MDI Child from another MDI Child using vb.net - vb.net

I need Some help in this case.
I have 3 Form (Main Form , Form1 , Form 2)
Main Form That is The Parent Form (ISCONTAINER = true)
Form 1 Is child for Main Form And In the same time Parent for Form2
Form 2 Is child for Form 1.
This pic that I need to be
Please I need code in vb.net
In MainForm I Write this code:
Me.IsMdiContainer = True
With Form1
.MdiParent = Me
.Show()
End With
In Form 2 I write this code:
With Form2
.MdiParent = CType(Me.Parent.Parent, MainForm)
.Show()
End With
The Form 1 opened as child for MainForm but Form2 doesn't

Related

How can I manage other forms under the main form?

I am trying to manage form2 to form9 under the main form1 in my project.
form1 contains a menustrip and from that I call the other forms with code
form3.show()
The problem is when I minimize form1 the other forms still stand alone and I must minimize all forms individually
I want one main form - form1 - that I can use to open other forms under their windows.
So form1 minimize than all other forms also minimize.
What you could do is work with the tabcontrol.
U put a tabcontrol on your mainForm and everytime u wanna open a new form u just add that form to a tabcontrolpage.
The code would look like this
Dim frm = New form1
Dim page = New C1DockingTabPage
page.Text = frm.Text
frm.ws_Employee_UID.Text = ws_Employee_UID.Text
frm.TopLevel = False
frm.FormBorderStyle = BorderStyle.None
frm.ControlBox = False
page.Controls.Add(frm)
Me.C1DockingTab1.TabPages.Add(page)
frm.Show()
page.Show()
or like said u could learn MDI, but i prefer the TabControl.

How to open child forms positioned within MDI parent in VB.NET?

How do we arrange child forms in a parent MDI window? I'm able to call and display a child form from a menu on the parent, but the child pops up outside the parent - I want it to actually be inside the parent. I've checked in C# and VB.Net solutions but they all say pretty much the same, i.e. try to access LayoutMDI, such as here:
http://msdn.microsoft.com/en-us/library/x9fhk181.aspx
The problem is, where do I access this? When I'm in the code of my MDI parent, Me.LayoutMdi is not recognized. In which part of the application do I put the Me.LayoutMDI code?
Edit
The Me.LayoutMDI code worked in the parent after all. I'd been trying for a while but don't know where I was going wrong.
However, the child continues to pop up out of the parent. Here's an image of how that happens. The broader form in the back is the parent, and the one with the gridview and two buttons is the new child that popped up. I want it to pop up "Docked" within the parent.
If your form is "outside" the MDI parent, then you most likely didn't set the MdiParent property:
Dim f As New Form
f.MdiParent = Me
f.Show()
Me, in this example, is a form that has IsMdiContainer = True so that it can host child forms.
For re-arranging the child form layout, you just call the method from your MdiContainer form:
Me.LayoutMdi(MdiLayout.Cascade)
The MdiLayout enum also has tiling and arrange icons values.
Dont set MDI Child property from MDIForm
In Chileform Load event give the below code
Dim l As Single = (MDIForm1.ClientSize.Width - Me.Width) / 2
Dim t As Single = ((MDIForm1.ClientSize.Height - Me.Height) / 2) - 30
Me.SetBounds(l, t, Me.Width, Me.Height)
Me.MdiParent = MDIForm1
end
try this code
You will want to set the MdiParent property of your new form to the name of the MDI parent form, as follows:
dim form as new yourform
form.show()
form.MdiParent = nameParent
Private Sub FileMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) handles FileMenu.Click
Form1.MdiParent = Me
Form1.Dock = DockStyle.Fill
Form1.Show()
End Sub
Try adding a button on mdi parent and add this code' to set your mdi child inside the mdi parent. change the yourchildformname to your MDI Child's form name and see if this works.
Dim NewMDIChild As New yourchildformname()
'Set the Parent Form of the Child window.
NewMDIChild.MdiParent = Me
'Display the new form.
NewMDIChild.Show()
Try the code below and.....
1 - change the name of the MENU as in my sample the menuitem was called 'Form7ToolStripMenuItem_Click'
2 - make SURE to paste it into an MDIFORM and not just a basic FORM
Then let me know if the CHILD form still shows OUTSIDE the parent form
Private Sub Form7ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Form7ToolStripMenuItem.Click
Dim NewForm As System.Windows.Forms.Form
NewForm = New System.Windows.Forms.Form
'USE THE NEXT LINE - to add an existing CUSTOM form you already have
'NewForm = Form7
NewForm.Width = 400
NewForm.Height = 250
NewForm.MdiParent = Me
NewForm.Text = "CAPTION"
NewForm.Show()
DockChildForm(NewForm, "left") 'dock left
'DockChildForm(NewForm, "right") 'dock right
'DockChildForm(NewForm, "top") 'dock top
'DockChildForm(NewForm, "bottom") 'doc bottom
'DockChildForm(NewForm, "full") 'fill the client area (maximise the child INSIDE the parent)
'DockChildForm(NewForm, "Anything-Else") 'center the form
End Sub
Private Sub DockChildForm(ByRef Form2Dock As Form, ByVal Position As String)
Dim XYpoint As Point
Select Case Position
Case "left"
Form2Dock.Dock = DockStyle.Left
Case "top"
Form2Dock.Dock = DockStyle.Top
Case "right"
Form2Dock.Dock = DockStyle.Right
Case "bottom"
Form2Dock.Dock = DockStyle.Bottom
Case "full"
Form2Dock.Dock = DockStyle.Fill
Case Else
XYpoint = New Point
XYpoint.X = ((Me.ClientSize.Width - Form2Dock.Width) / 2)
XYpoint.Y = ((Me.ClientSize.Height - Form2Dock.Height) / 2)
Form2Dock.Location = XYpoint
End Select
End Sub
Try Making the Child Form's StartPosition Property set to Center Parent. This you can select from the form Properties.
See this page for the solution!
https://msdn.microsoft.com/en-us/library/7aw8zc76(v=vs.110).aspx
I was able to implement the Child form inside the parent.
In the Example below Form2 should change to the name of your child form.
NewMDIChild.MdiParent=me is the main form since the control that opens (shows) the child form is the parent or Me.
NewMDIChild.Show() is your child form since you associated your child form with Dim NewMDIChild As New Form2()
Protected Sub MDIChildNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
Dim NewMDIChild As New Form2()
'Set the Parent Form of the Child window.
NewMDIChild.MdiParent = Me
'Display the new form.
NewMDIChild.Show()
End Sub
Simple and it works.

How to ensure only one instance of a child form is created by a parent mdi form in VB.NET

I have a button on a parent form that can create new Child forms.
However, I don't want more than one instance of each form to be created. I tried putting a public boolean on the parent MDI form:
Dim ChildForm As Boolean = False
And at the point where the child form is created:
ChildFormThere = True
And in the child form's "Leave" event, I thought I could do this:
Me.MdiParent.ChildFormThere = False
But it doesn't recognize the ChildFormThere variable... How can this be done then?
How about something like this. The idea is that if the form has already been created you switch to it, otherwise create one. This assumes you are setting mdiParent correctly when creating the child forms. This code would need to be run on the mdiParent, or have a reference to it to access the MdiChildren property.
For Each f In Me.MdiChildren
If TypeOf (f) Is Form1 Then
f.Show()
Exit Sub
End If
Next
Dim frm As New Form1
frm.Show()
Perhaps instead of:
dim ChildFormThere as Boolean = False ' Or True
You could do:
dim ChildForm as New ChildFormClass
' On Create Button Click:
ChildForm.Visible = True
This way it's always the same instance, so you simple have to manage if it is visible or not.

How to pass the value to current active form

Using VB.Net
I have main form name as form1 and popup form name as form2
Form1
tab button - for creating mulitple copy of form1 at runtime...
Creation of mulitple from1 at runtime code
form1 code
Dim mEntryForm As form1
mEntryForm = New form1
mEntryForm.Show()
The above code is creating a same copy of form1 at runtime.
Now i want to pass the value from popup form to current activeform
Code for sending the value to form1 from popup form (form2)
form2code
form1.textbox1.text = "100"
The above code is going to form1 textbox, instead of active form (mentryform)
How to solve this problem.
Need Vb.net code help
Although I totaly agree with the comments about your question I ll try to give you a solution
Add a property to your Form2
name smtng like ActiveForm1 as form1
now because I haven't understand completey your concept:
-> if Form2 is a ShowDialog form then you cannot change the active form1.
You need to set the property ActiveForm1
dim frm2 as new form2
frm2.ActiveForm1=me
frm2.ShowDialog
->if Form2 is not a ShowDialog that means that you can change the active form1
then you need to add this lines of code when a form1 is activated
frm2.ActiveForm1=me
Now in form2:
me.ActiveForm1.textbox1.text = "100"
I hope that I helped you.

How to open a MDI child form using a MenuList on the main MDI parent form

I have a MDI Parent form created with a MenuList, I also have the MDI child form created... how do I go about using the MenuList to open the MDI child form within the parent form?
I ended up added within the event this code:
'Create a new instance of Form2
Dim NewMDIChild As New frmProductMaintenance()
'Set the parent of the MDI child form.
NewMDIChild.MdiParent = Me
'Display the new form.
NewMDIChild.Show()