monkey magic
06-14-2002, 06:20 AM
Hi i was just wondering if anyone can help?
i would like to have a main form (main window) and have all other forms (windows) load within that. i know it is possibla and probably quite easy because i have seen it done many times. i just never read into it.
any ideas/examples would be greatly appreciated :D
rowanjl
06-14-2002, 06:42 AM
Do you not know how to use a MDI form?
ChiefRedBull
06-14-2002, 07:48 AM
Just to expand on rownji's answer - add an MDI (Multiple Document Interface) form to your project. For any forms that you wish to appear inside the MDI, set their .MDIChild property = True.
Road Runner
06-14-2002, 07:55 AM
There is a quick tutorial here (http://www.dcs.napier.ac.uk/hci/VB50/HTML/tutorial_14.html) on how to use MDI Forms.
Shane
monkey magic
06-14-2002, 12:56 PM
Thanks a lot
gonna have a look at the tutorial now :D
Cogen
06-14-2002, 01:14 PM
Nice tutorial shanebourke!
While reading the tutorial, one thing stood out to me, and I was wondering if you (or anyone) could tell me if this is the best way to do it?
Private Sub mnuNew_Click()
Dim frmNew As New frmChild ' Create a new instance of a child form
frmNew.Show
frmNew.Caption = "MDI Child #" & (forms.Count - 1)
End Sub
Dim frmNew As New frmChild ???
I was just wondering, wouldn't it be better to use :
Dim frmNew As frmChild
Set frmNew = New frmChild
From my training, I have been taught that it's usually not a good idea to declare and instantiate a variable on the same line, but maybe you have to for forms, I'm not sure? (hence me asking)
ChiefRedBull
06-14-2002, 01:33 PM
If you're going to instantiate the object immediately, then I see no reason to not merge the two lines.
The problem from doing this comes when you have serveral objects all instantiated when the app starts, potentially not being used for a long time, eating up memory.
monkey magic
06-14-2002, 01:45 PM
yeah thanks shanebourke
for the tutorial, it was nice and easy to follow
Cogen
06-14-2002, 02:04 PM
I knew there was a quote I read somewhere ...
Note: Avoid using the more compact syntax, Dim objCustomer As New Customer, to create an object. Although this saves a line of code, Visual Basic will not create the object until it is used. This syntax causes Visual Basic to insert checks inside your code to determine if the object is created yet, and to create it when it is first used. The overall result is less efficient code.
Doesn't that hold true for Forms also?
ChiefRedBull
06-14-2002, 03:38 PM
Yes it holds true for any object. The point is, that if you're going to use the object straight away, then only one exra call is made ( I believe it's to QueryInterface or something.... ).
True, this is one unnecessary call, but the difference would be negligable.