I have a parent form called MdiForm1 within it I open frm1 which is a child form. SO everything is great at this point - now I need to open another form within frm1 - lets call that frmX and here's where my issue arises - I previously had declared it as mdichild form, and did mdichild.show - however the issue comes up because when this form opens (it covers about 1/3 of frm1 - which is already open) and user clicks outside of the frmX - it simply disapears. So I tried to .showDialog() however am unable to do that because it's not Top level and is a mdiChild therefore won't let me .showdialog(). here's my code...
Private Sub cmd1_Click(sender As Object, e As EventArgs) Handles cmd1.Click
Dim NewMDIChild As New Frmx()
'Set the Parent Form of the Child window.
NewMDIChild.MdiParent = MDI1
'Display the new form
NewMDIChild.Top = 310
NewMDIChild.Left = 36
NewMDIChild.Width = 897
Form that is not a top-level form cannot be displayed as a modal
dialog box. Remove the form from any parent form before calling
dim frmX as New Form
'specifying Top/Left/Width but that doesn't do anything, basically opens an empty form elsewhere on the screen.
Dim frmxName As New FrmX()
frmxName.MdiParent = Me.MdiParent
frmxName.Top = 310
frmxName.Left = 36
frmxName.Width = 897
Set the new form's MDI parent to the controlling form's MDI parent
In the MDI parent I called Form1. This form has the property IsMdiContainer = True
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim myFrmX As New frmX myFrmX.MdiParent = Me myFrmX.Show() End Sub End Class
And in frmX with a button on it
Public Class frmX Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim f As New Form f.MdiParent = Me.MdiParent f.Text = "frmY" f.Show() End Sub End Class
Clicking the button creates new Forms, which are shown to be MDI children of the main form below
Or if you just want a dialog window, forgo the MDI business, and just show dialog
Public Class frmX Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim f As New Form f.Text = "frmY" f.ShowDialog() End Sub End Class
Now frmY has focus until it's closed.