?
Solved

Open form inside a MDI form

Posted on 2003-03-11
4
Medium Priority
?
170 Views
Last Modified: 2010-05-01
I tried to open a form inside a MDI. TO open the form i used:
  load myform
  myform.show

My problem is that myform not opened with the size that I put in the properties of the form. The only way that i fourn to do that is put the real size in the load event.

Anybody know other way to do that.

Regards
Alejandro
0
Comment
Question by:aleycris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 8112500
I've found this to be quite an annoyance.  One way that has worked for me (with smaller forms) is to maximize the MDI form, load/show the child form, then restore the MDI form.

Actually, I think that I shoved the MDI form to the lower right corner, set its width/height to a large number, loaded the child form, then reset the MDI form to its previous location/size.  I did this so it wouldn't flash on the screen.

0
 

Author Comment

by:aleycris
ID: 8112789
I used that but it doesn't work

Any idea?
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 8112958
It seems that there are two things that control it, but mainly it's the start-up size of the MDI form.

If you start with the MDI form at maximum size in design mode, then the this code seems to work:

Private Sub MDIForm_Load()
  Me.WindowState = vbNormal

  Form1.Show

  ' resize the MDI form to match the child window, it desired, or whatever size you choose
  Me.Width = Form1.Width + (Me.Width - Me.ScaleWidth)
  Me.Height = Form1.Height + (Me.Height - Me.ScaleHeight)
End Sub

Again, the MDI form has to be sufficiently large in design mode for this to work.
0
 
LVL 3

Accepted Solution

by:
QJohnson earned 150 total points
ID: 8116586
VB has its own ideas about the size and locations with which Child forms should show themselves.

But you can override this behavior simply by setting those properties in the Form_Load event.

My own preference it to have form-level variables for the default height and width so that I can also use them to prevent re-sizing to lower values.  But you certainly don't need to incorporate that.

If you do:

In General Declarations:
Private mnStartWidth as Long
Private mnStartHeight as Long

In Form_Load:
mnStartWidth = 6000    ' or whatever value you set at design time
mnStartHeight = 3500   ' your design time height

me.move 0, 0, mnStartWidth, mnStartHeight

this assumes you want to show the form in the top left corner of your MDI parent (i.e, at 0,0).  If you want the form centered, you have to just use something like:

me.move (MDIFormName.ScaleWidth - mnStartWidth) / 2, _
               (MDIFormName.ScaleHeight - mnStartHeight) / 2, _
               (mnStartWidth, mnStartHeight)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question