Solved

Sizing of forms in an MDI application (VB6)

Posted on 2002-07-04
5
280 Views
Last Modified: 2008-03-04
I have an MDI application with a number of different forms so it isn't an MDI application in the true sense of the word.

When I load forms which I have set to sizable, they don't appear as they same size that I have designed them which means the controls appear in the wrong place.

I have a control repositioning routine but it requires that the controls are in the right place when the form is first loaded to calculate their positions on subsequent resizes.

Currently I'm hard coding the width and height from the design time properties and then setting these when the form loads but there must be a better way...

Does anyone know of one?
0
Comment
Question by:rd707
5 Comments
 
LVL 3

Expert Comment

by:carruina
Comment Utility
You can use something like this

Insert this code in a Module

Public Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, _
  lpRect As RECT) As Long
Public Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
 
Public Type RECT
     Left As Long
     Top As Long
     Right As Long
     Bottom As Long
End Type

In the Load of the Subform insert label and Grids with the correct names


Dim Clientrect As RECT
GetClientRect GetParent(Me.hWnd), Clientrect

'Resize the form to the Client Area Parent  
Me.Height = Clientrect.Bottom * Screen.TwipsPerPixelY
Me.Width = Clientrect.Right * Screen.TwipsPerPixelX


GetClientRect Me.hWnd, Clientrect
   
'Resize and position the componente in function of the Client Area of the form

LblProjects.Left = 0
LblProjects.Top = 0

GridProyectos.Left = 0
GridProyectos.Top = 0 + LblProjects.Height
GridProyectos.Height = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 2) - LblProjects.Height
GridProyectos.Width = (Clientrect.Right * Screen.TwipsPerPixelX) / 2

Me.LblPhases.Left = 0
Me.LblPhases.Top = (Clientrect.Bottom * Screen.TwipsPerPixelY) / 2
Me.MSFlexGrid1.Left = 0
Me.MSFlexGrid1.Top = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 2) + LblPhases.Height
Me.MSFlexGrid1.Height = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 2) - LblPhases.Height
Me.MSFlexGrid1.Width = (Clientrect.Right * Screen.TwipsPerPixelX)


Me.LblPlants.Left = (Clientrect.Right * Screen.TwipsPerPixelX) / 2
Me.LblPlants.Top = 0

GridMasPro.Left = (Clientrect.Right * Screen.TwipsPerPixelX) / 2
GridMasPro.Top = 0 + LblPlants.Height
GridMasPro.Height = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 4) - LblPlants.Height
GridMasPro.Width = (Clientrect.Right * Screen.TwipsPerPixelX) / 2


Me.LblLevels.Left = (Clientrect.Right * Screen.TwipsPerPixelX) / 2
Me.LblLevels.Top = (Clientrect.Bottom * Screen.TwipsPerPixelY) / 4

GridNiveles.Left = (Clientrect.Right * Screen.TwipsPerPixelX) / 2
GridNiveles.Top = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 4) + Me.LblLevels.Height
GridNiveles.Height = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 4) - Me.LblLevels.Height
GridNiveles.Width = (Clientrect.Right * Screen.TwipsPerPixelX) / 4
0
 
LVL 3

Expert Comment

by:carruina
Comment Utility
You can use something like this

Insert this code in a Module

Public Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, _
  lpRect As RECT) As Long
Public Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
 
Public Type RECT
     Left As Long
     Top As Long
     Right As Long
     Bottom As Long
End Type

In the Load of the Subform insert label and Grids with the correct names


Dim Clientrect As RECT
GetClientRect GetParent(Me.hWnd), Clientrect

'Resize the form to the Client Area Parent  
Me.Height = Clientrect.Bottom * Screen.TwipsPerPixelY
Me.Width = Clientrect.Right * Screen.TwipsPerPixelX


GetClientRect Me.hWnd, Clientrect
   
'Resize and position the componente in function of the Client Area of the form

LblProjects.Left = 0
LblProjects.Top = 0

GridProyectos.Left = 0
GridProyectos.Top = 0 + LblProjects.Height
GridProyectos.Height = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 2) - LblProjects.Height
GridProyectos.Width = (Clientrect.Right * Screen.TwipsPerPixelX) / 2

Me.LblPhases.Left = 0
Me.LblPhases.Top = (Clientrect.Bottom * Screen.TwipsPerPixelY) / 2
Me.MSFlexGrid1.Left = 0
Me.MSFlexGrid1.Top = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 2) + LblPhases.Height
Me.MSFlexGrid1.Height = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 2) - LblPhases.Height
Me.MSFlexGrid1.Width = (Clientrect.Right * Screen.TwipsPerPixelX)


Me.LblPlants.Left = (Clientrect.Right * Screen.TwipsPerPixelX) / 2
Me.LblPlants.Top = 0

GridMasPro.Left = (Clientrect.Right * Screen.TwipsPerPixelX) / 2
GridMasPro.Top = 0 + LblPlants.Height
GridMasPro.Height = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 4) - LblPlants.Height
GridMasPro.Width = (Clientrect.Right * Screen.TwipsPerPixelX) / 2


Me.LblLevels.Left = (Clientrect.Right * Screen.TwipsPerPixelX) / 2
Me.LblLevels.Top = (Clientrect.Bottom * Screen.TwipsPerPixelY) / 4

GridNiveles.Left = (Clientrect.Right * Screen.TwipsPerPixelX) / 2
GridNiveles.Top = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 4) + Me.LblLevels.Height
GridNiveles.Height = ((Clientrect.Bottom * Screen.TwipsPerPixelY) / 4) - Me.LblLevels.Height
GridNiveles.Width = (Clientrect.Right * Screen.TwipsPerPixelX) / 4
0
 
LVL 18

Accepted Solution

by:
mdougan earned 50 total points
Comment Utility
There is the old joke about the guy that goes to the doctor and says "doc, it hurts when I raise my arm like this", and the doctor replies "so, don't raise your arm like that".

When you are choosing a design for your application, you have to consider all the implications.  If you want your forms to be "children" of a main window, and you choose an MDI parent as the main window, and make the other forms MDI Child windows, then you are telling the system that you want the MDI Parent to manage the size an layout and position (tiling, cascading etc)of the child windows.

If you don't want this behavior, then don't choose an MDI style of design.

However, if you really want the MDI parent to contain the children, you can try setting the border style of the children to fixed.  This should keep them from being resized.  However, if you want them to be resizable, but you just don't like the size that the MDI parent makes them, then I don't know of any other choice than to have code in the form's resize event that checks the new size, and if it it too small, or not the right shape, you can reset the size to your minimum.

Const MINHEIGHT = 4000
Const MINWIDTH = 6000

Private Sub Form_Resize()
If me.Height < MINHEIGHT Then
   me.Height = MINHEIGHT
End if

If me.Width < MINWIDTH Then
   me.Width = MINWIDTH
End if
End Sub
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Hi rd707,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept mdougan's comment(s) as an answer.

rd707, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
Comment Utility
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now