Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

Sizing of forms in an MDI application (VB6)

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
rd707
Asked:
rd707
1 Solution
 
carruinaCommented:
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
 
carruinaCommented:
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
 
mdouganCommented:
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
 
DanRollinsCommented:
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
 
Computer101Commented:
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now