Solved

Sizing of forms in an MDI application (VB6)

Posted on 2002-07-04
5
284 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
ID: 7130191
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
ID: 7130238
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
ID: 7132012
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
ID: 7990629
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
ID: 8050702
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

820 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