Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sizing of forms in an MDI application (VB6)

Posted on 2002-07-04
5
Medium Priority
?
290 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
[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
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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
Suggested Courses

715 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