MDI Problem

liam

Member
Joined
Jun 8, 2004
Messages
23
Programming Experience
Beginner
I'm having a problem showing a form coming from an mdichild. How can I make that new form open also inside the MDI form?

The problem is when I click the New Account menuitem an mdichild is opened and when the mdichild is opened i have an ok button there when it is clicked it should open another form that should also be inside the mdi form. But it opens outside the mdi.

Another problem is that my login screen doesn't close when i open the mdimain. It should be closed once the mdiform is already opened.

Thanks in advance I hope someone can help me on this.
 
Another problem is that my login screen doesn't close when i open the mdimain. It should be closed once the mdiform is already opened.
your login screen run in the mdimain..
jst like this
VB.NET:
   'in the mdimain form
   public logged as boolean = false
   
   'in the mdimain form load
   Dim x As New loginform()
  Me.AddOwnedForm(x)
  x.ShowDialog()
  If logged = False Then
   	Application.DoEvents()
  End If
   
   'in the loginform
   dim m as mdimain
   
   'in the loginform load
   m = me.owner
   
   'in the button ok
   if txtusername.text = "blah..." and txtpassword.text = "password" then
      m.logged = true
      close()
   end if
   
   'in the cancel button
   m.close()
   close()

hope it helps..
 
Last edited:
The problem is when I click the New Account menuitem an mdichild is opened and when the mdichild is opened i have an ok button there when it is clicked it should open another form that should also be inside the mdi form. But it opens outside the mdi.
compute the width of the mdimain divide it by 2 and subtract it w/ the size of the mdichild divided by 2. as well as the height

set this as constructor of your child forms
VB.NET:
    Dim pp As Point
    Public Sub New(ByVal p As Point, ByVal s As Size)
 	  MyBase.New()
 
 	  'This call is required by the Windows Form Designer.
 	  InitializeComponent()
 
 	  pp = New Point(p.X + (s.Width / 2) - Me.Width / 2, p.Y + (s.Height / 2) - Me.Height / 2)
 
 	  Me.DesktopLocation = pp
 	  'Add any initialization after the InitializeComponent() call
 
    End Sub
 'to call this constructor
 dim f as form
 f = new mdichild(new point(0, 0), me.size())
 f.show()
 f.mdiparent = me

hope it helps..
 
to close the login, do a frm.Close where frm is a reference to the login form.

to open an MDI form from a MdiChild:

VB.NET:
Dim frm As New frmMdiChild2()
frm.MdiParent = Me.MdiParent
frm.Show()

This code is in the first MdiChild; frmMdiChild2 is the second child form, it will be opened in the same Parent as the calling form.
 
BTW if you use showdialog()
to call the constructor
VB.NET:
 dim f as new mdichild(me.desktoplocation, me.Size)
 f.showdialog()
 f.mdiparent = me

hope it helps..
happy coding...
 
Back
Top